Skip to content

Don't erase type object args in diagnostics #18352

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

Merged
merged 2 commits into from
Dec 28, 2024

Conversation

hauntsaninja
Copy link
Collaborator

Fixes #16875

This comment has been minimized.

Copy link
Contributor

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

Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/clients.py:2428: error: Argument 1 to "get_type_dependency" of "Client" has incompatible type "type[SingleStoreCache[Any]]"; expected "type[SingleStoreCache[Application]] | type[None]"  [arg-type]
+ tanjun/clients.py:2428: error: Argument 1 to "get_type_dependency" of "Client" has incompatible type "type[SingleStoreCache[AuthorizationApplication]]"; expected "type[SingleStoreCache[Application]] | type[None]"  [arg-type]

operator (https://github.com/canonical/operator)
- ops/charm.py:1756: error: Incompatible types in assignment (expression has type "object", variable has type "type[list[Any]]")  [assignment]
+ ops/charm.py:1756: error: Incompatible types in assignment (expression has type "object", variable has type "type[list[str]]")  [assignment]

steam.py (https://github.com/Gobot1234/steam.py)
- steam/client.py:1276: error: Invalid self argument "type[TradeOffer[Any, Any, Any]]" to attribute function "_from_history" with type "Callable[[type[TradeOffer[MovedItem[UserT], MovedItem[ClientUser], UserT]], ConnectionState, TradeOfferHistoryTrade, Sequence[Description]], TradeOffer[MovedItem[UserT], MovedItem[ClientUser], UserT]]"  [misc]
+ steam/client.py:1276: error: Invalid self argument "type[TradeOffer[ReceivingAssetT, SendingAssetT, UserT]]" to attribute function "_from_history" with type "Callable[[type[TradeOffer[MovedItem[UserT], MovedItem[ClientUser], UserT]], ConnectionState, TradeOfferHistoryTrade, Sequence[Description]], TradeOffer[MovedItem[UserT], MovedItem[ClientUser], UserT]]"  [misc]

ibis (https://github.com/ibis-project/ibis)
- ibis/expr/operations/__init__.py:8: error: Incompatible import of "Literal" (imported name has type "<typing special form>", local name has type "type[Literal[Any]]")  [assignment]
+ ibis/expr/operations/__init__.py:8: error: Incompatible import of "Literal" (imported name has type "<typing special form>", local name has type "type[Literal[T]]")  [assignment]
- ibis/expr/operations/__init__.py:13: error: Incompatible import of "Literal" (imported name has type "<typing special form>", local name has type "type[Literal[Any]]")  [assignment]
+ ibis/expr/operations/__init__.py:13: error: Incompatible import of "Literal" (imported name has type "<typing special form>", local name has type "type[Literal[T]]")  [assignment]
- ibis/expr/operations/__init__.py:14: error: Incompatible import of "Literal" (imported name has type "<typing special form>", local name has type "type[Literal[Any]]")  [assignment]
+ ibis/expr/operations/__init__.py:14: error: Incompatible import of "Literal" (imported name has type "<typing special form>", local name has type "type[Literal[T]]")  [assignment]
- ibis/expr/operations/__init__.py:20: error: Incompatible import of "Literal" (imported name has type "<typing special form>", local name has type "type[Literal[Any]]")  [assignment]
+ ibis/expr/operations/__init__.py:20: error: Incompatible import of "Literal" (imported name has type "<typing special form>", local name has type "type[Literal[T]]")  [assignment]
- ibis/expr/types/relations.py:4401: error: Argument 1 to "map" has incompatible type "type[tuple[Any, ...]]"; expected "Callable[[list[str]], str]"  [arg-type]
+ ibis/expr/types/relations.py:4401: error: Argument 1 to "map" has incompatible type "type[tuple[_T_co, ...]]"; expected "Callable[[list[str]], str]"  [arg-type]

werkzeug (https://github.com/pallets/werkzeug)
- tests/test_wrappers.py:1057: error: Incompatible types in assignment (expression has type "type[tuple[Any, ...]]", variable has type "type[list[Any]]")  [assignment]
+ tests/test_wrappers.py:1057: error: Incompatible types in assignment (expression has type "type[tuple[_T_co, ...]]", variable has type "type[list[Any]]")  [assignment]
- tests/test_wrappers.py:1059: error: Non-overlapping identity check (left operand type: "type[list[str]]", right operand type: "type[tuple[Any, ...]]")  [comparison-overlap]
+ tests/test_wrappers.py:1059: error: Non-overlapping identity check (left operand type: "type[list[str]]", right operand type: "type[tuple[_T_co, ...]]")  [comparison-overlap]
- tests/test_local.py:231: error: Non-overlapping identity check (left operand type: "type[list[Any]]", right operand type: "type[LocalProxy[Any]]")  [comparison-overlap]
+ tests/test_local.py:231: error: Non-overlapping identity check (left operand type: "type[list[Any]]", right operand type: "type[LocalProxy[T]]")  [comparison-overlap]

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, I wonder why we were using erase_type() in the first place.

@hauntsaninja
Copy link
Collaborator Author

Dates to #3374 (comment)
I think this is fine, it's not worth the confusion. Other type checkers report similar diagnostics as mypy does with this PR.

@hauntsaninja hauntsaninja merged commit 44bf7e5 into python:master Dec 28, 2024
18 checks passed
@hauntsaninja hauntsaninja deleted the eraser branch December 28, 2024 22:46
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.

Using numpy types conditionally gives confusing [assignment] error
2 participants