Skip to content

Correctly handle TypeOfAny.from_another_any #15497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

ilevkivskyi
Copy link
Member

Fixes #15253

The fix is trivial so I am not going to wait for a review, will just check the primer. Also I am trying something new here: adding a unit test.

@github-actions

This comment has been minimized.

@ilevkivskyi
Copy link
Member Author

And of course this uncovered a big can of worms: currently TypeOfAny.special_form is used in a lot of places where it is a totally real Any but the source Any is not accessible, for example an attribute access on a class with fallback_to_any. Overload ambiguity uses has_any_type() and will actually randomly choose first matching overload for those "special form" Any, while it actually should count them as real.

The only reasonable solution I see here is to introduce a new kind of Any, and move some part of existing special_form Anys to it (and there are now ~100 uses). This new type will be counted as a real one (for both --disallow-any-expr and for overload ambiguity etc), but this is actually a big chunk of work, so I don't really want to do it.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/arrays/interval.py:1019: error: Incompatible types in assignment (expression has type "DatetimeArray | TimedeltaArray | ndarray[Any, Any]", variable has type "ndarray[Any, dtype[Any]]")  [assignment]
+ pandas/core/arrays/sparse/array.py:1879: error: Incompatible types in assignment (expression has type "ExtensionArray | ndarray[Any, Any]", variable has type "ndarray[Any, Any]")  [assignment]
+ pandas/core/window/rolling.py:1683: error: "bool" has no attribute "astype"  [attr-defined]
+ pandas/core/window/rolling.py:1730: error: "bool" has no attribute "astype"  [attr-defined]
+ pandas/core/groupby/groupby.py:5349: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[Any]]", variable has type "list[Any]")  [assignment]
+ pandas/core/groupby/generic.py:793: error: Incompatible types in assignment (expression has type "list[ndarray[Any, dtype[_SCT]]]", variable has type "list[ndarray[Any, dtype[signedinteger[Any]]]]")  [assignment]

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
- tests/test_pandas.py:245: error: Expression is of type "Any", not "Series[bool]"  [assert-type]
+ tests/test_pandas.py:245: error: Expression is of type "DataFrame", not "Series[bool]"  [assert-type]

optuna (https://github.com/optuna/optuna)
+ optuna/importance/_fanova/_tree.py:64: error: Incompatible types in assignment (expression has type "tuple[Any, ...]", variable has type "list[Any]")  [assignment]

schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/specs/openapi/schemas.py: note: In member "get_operation_by_reference" of class "BaseOpenAPISchema":
+ src/schemathesis/specs/openapi/schemas.py:315: error: Argument 2 to "chain" has incompatible type "Dict[str, Any]"; expected "Iterable[Dict[str, Any]]"  [arg-type]

scrapy (https://github.com/scrapy/scrapy)
+ scrapy/http/request/form.py:52: error: Argument 1 to "_set_url" of "Request" has incompatible type "Literal[b'']"; expected "str"  [arg-type]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive on _ (underscore) as variable name with disallow-any-expr
1 participant