-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Use namespaces for function type variables #17311
Conversation
This comment has been minimized.
This comment has been minimized.
I briefly looked at mypy_primer, at least some of the errors are real (people forget |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty reasonable to me although I'm new to MyPy.
It's an interesting read, we have (bigger) type variable identification issues in Pyre and seeing MyPy's logic + improvements to it is helpful!
|
||
def add_method( | ||
funcname: str, | ||
ret: Type, | ||
ret: Type | None, # None means use (patched) self-type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize we can't pass self_type anymore because the ids are now per method. Would it make sense to create a no-op class for this
class SelfTypeMarker:
pass
so that the type here would be
ret: Type | SelfTypeMarker
?
Given the comment here I don't think it makes that much difference to understandability of the implementation, but lifting the semantics to the type level probably makes callsites easier to read and will make things like signature help in the IDE more descriptive.
@@ -620,13 +627,13 @@ def add_method( | |||
|
|||
add_method( | |||
"_replace", | |||
ret=selftype, | |||
ret=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(all the calls in this block are examples of where I think the code is less readable now, and making a dummy SelfTypeMarker
class would help)
@@ -569,40 +570,46 @@ def add_field( | |||
add_field(Var("__match_args__", match_args_type), is_initialized_in_class=True) | |||
|
|||
assert info.tuple_type is not None # Set by update_tuple_type() above. | |||
tvd = TypeVarType( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the name "tvd" supposed to mean?
Glad to see it gone, the only thing I can even come up with is "type var default" but that doesn't seem like the best name for something that's only ever self type even in non-abbreviated form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"tvd" stays for TypeVarDef
which is not a thing since around couple years ago.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I went through the
@JukkaL @hauntsaninja This is ready for review, please take a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent! Bugs related to generics tend to be very confusing and hard to investigate. The clearer error messages are also nice.
Diff from mypy_primer, showing the effect of this PR on open source code: python-chess (https://github.com/niklasf/python-chess)
+ chess/__init__.py:1780: error: Argument 1 to "restore" of "_BoardState" has incompatible type "BoardT@root"; expected "BoardT@__init__" [arg-type]
+ chess/__init__.py:2328: error: Argument 1 to "append" of "list" has incompatible type "_BoardState[BoardT@push]"; expected "_BoardState[BoardT@__init__]" [arg-type]
+ chess/__init__.py:2428: error: Argument 1 to "restore" of "_BoardState" has incompatible type "BoardT@pop"; expected "BoardT@__init__" [arg-type]
+ chess/engine.py:926: error: Argument 1 to "_engine_terminated" of "BaseCommand" has incompatible type "ProtocolT@connection_lost"; expected "ProtocolT@__init__" [arg-type]
+ chess/engine.py:929: error: Argument 1 to "_engine_terminated" of "BaseCommand" has incompatible type "ProtocolT@connection_lost"; expected "ProtocolT@__init__" [arg-type]
+ chess/engine.py:969: error: Argument 1 to "_line_received" of "BaseCommand" has incompatible type "ProtocolT@_line_received"; expected "ProtocolT@__init__" [arg-type]
+ chess/engine.py:987: error: Incompatible types in assignment (expression has type "BaseCommand[ProtocolT@communicate, T]", variable has type "BaseCommand[ProtocolT@__init__, Any] | None") [assignment]
+ chess/engine.py:996: error: Argument 1 to "_cancel" of "BaseCommand" has incompatible type "ProtocolT@communicate"; expected "ProtocolT@__init__" [arg-type]
+ chess/engine.py:1000: error: Argument 1 to "_start" of "BaseCommand" has incompatible type "ProtocolT@communicate"; expected "ProtocolT@__init__" [arg-type]
+ chess/engine.py:1007: error: Argument 1 to "_cancel" of "BaseCommand" has incompatible type "ProtocolT@communicate"; expected "ProtocolT@__init__" [arg-type]
pip (https://github.com/pypa/pip)
- src/pip/_internal/cli/progress_bars.py:90: error: Argument 2 to "_rich_progress_bar" has incompatible type "int | None"; expected "int" [arg-type]
+ src/pip/_internal/cli/progress_bars.py:90: error: Argument "size" to "_rich_progress_bar" has incompatible type "int | None"; expected "int" [arg-type]
steam.py (https://github.com/Gobot1234/steam.py)
- steam/ext/commands/commands.py:741: error: Overloaded function signatures 2 and 3 overlap with incompatible return types [overload-overlap]
- steam/ext/commands/commands.py:851: error: Overloaded function implementation cannot satisfy signature 2 due to inconsistencies in how they use type variables [misc]
pandas (https://github.com/pandas-dev/pandas)
- pandas/core/window/rolling.py:1496: error: Argument 3 to "roll_apply" has incompatible type "bool | bool_"; expected "bool" [arg-type]
+ pandas/core/window/rolling.py:1496: error: Argument "raw" to "roll_apply" has incompatible type "bool | bool_"; expected "bool" [arg-type]
- pandas/core/tools/datetimes.py:1001: error: Argument 6 to "_convert_listlike_datetimes" has incompatible type "bool | Literal[_NoDefault.no_default]"; expected "bool" [arg-type]
+ pandas/core/tools/datetimes.py:1001: error: Argument "exact" to "_convert_listlike_datetimes" has incompatible type "bool | Literal[_NoDefault.no_default]"; expected "bool" [arg-type]
- pandas/core/groupby/groupby.py:4374: error: Argument 3 to "group_quantile" has incompatible type "str"; expected "Literal['linear', 'lower', 'higher', 'nearest', 'midpoint']" [arg-type]
+ pandas/core/groupby/groupby.py:4374: error: Argument "interpolation" to "group_quantile" has incompatible type "str"; expected "Literal['linear', 'lower', 'higher', 'nearest', 'midpoint']" [arg-type]
- pandas/tests/indexes/test_base.py:148: error: Unexpected keyword argument "data" for "RangeIndex" [call-arg]
+ pandas/tests/indexes/test_base.py:1603: error: Unexpected keyword argument "data" for "RangeIndex" [call-arg]
starlette (https://github.com/encode/starlette)
- starlette/routing.py:36: error: Too few arguments for "run_in_threadpool" [call-arg]
Tanjun (https://github.com/FasterSpeeding/Tanjun)
+ tanjun/commands/slash.py:373: error: Type argument "_SlashCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/slash.py:373: error: Type argument "_SlashCallbackSigT" of "MessageCommand" must be a subtype of "Callable[[MessageContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/slash.py:1270: error: Type argument "_SlashCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/slash.py:1270: error: Type argument "_SlashCallbackSigT" of "MessageCommand" must be a subtype of "Callable[[MessageContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/slash.py:1324: error: Type argument "_SlashCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/slash.py:1324: error: Type argument "_SlashCallbackSigT" of "MessageCommand" must be a subtype of "Callable[[MessageContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:101: error: Type argument "_MessageCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:101: error: Type argument "_MessageCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:124: error: Type argument "_MessageCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:124: error: Type argument "_MessageCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:483: error: Type argument "_OtherCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:483: error: Type argument "_OtherCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:506: error: Type argument "_OtherCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:506: error: Type argument "_OtherCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/menu.py:172: error: Type argument "_MessageCallbackSigT" of "MessageCommand" must be a subtype of "Callable[[MessageContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/menu.py:172: error: Type argument "_MessageCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/menu.py:182: error: Incompatible return value type (got "MenuCommand[_MessageCallbackSigT@__init__, Literal[CommandType.MESSAGE]]", expected "MenuCommand[_MessageCallbackSigT@decorator, Literal[CommandType.MESSAGE]]") [return-value]
+ tanjun/commands/menu.py:299: error: Type argument "_UserCallbackSigT" of "MessageCommand" must be a subtype of "Callable[[MessageContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/menu.py:299: error: Type argument "_UserCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/menu.py:309: error: Incompatible return value type (got "MenuCommand[_UserCallbackSigT@__init__, Literal[CommandType.USER]]", expected "MenuCommand[_UserCallbackSigT@decorator, Literal[CommandType.USER]]") [return-value]
+ tanjun/commands/menu.py:369: error: Type argument "_UserCallbackSigT" of "MessageCommand" must be a subtype of "Callable[[MessageContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/menu.py:369: error: Type argument "_UserCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/menu.py:405: error: Type argument "_MessageCallbackSigT" of "MessageCommand" must be a subtype of "Callable[[MessageContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/menu.py:405: error: Type argument "_MessageCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
vision (https://github.com/pytorch/vision)
- torchvision/models/video/swin_transformer.py:518: error: Argument 2 to "VideoClassification" has incompatible type "tuple[int]"; expected "tuple[int, int]" [arg-type]
+ torchvision/models/video/swin_transformer.py:518: error: Argument "resize_size" to "VideoClassification" has incompatible type "tuple[int]"; expected "tuple[int, int]" [arg-type]
- torchvision/models/video/swin_transformer.py:549: error: Argument 2 to "VideoClassification" has incompatible type "tuple[int]"; expected "tuple[int, int]" [arg-type]
+ torchvision/models/video/swin_transformer.py:549: error: Argument "resize_size" to "VideoClassification" has incompatible type "tuple[int]"; expected "tuple[int, int]" [arg-type]
- torchvision/models/video/swin_transformer.py:580: error: Argument 2 to "VideoClassification" has incompatible type "tuple[int]"; expected "tuple[int, int]" [arg-type]
+ torchvision/models/video/swin_transformer.py:580: error: Argument "resize_size" to "VideoClassification" has incompatible type "tuple[int]"; expected "tuple[int, int]" [arg-type]
- torchvision/models/video/swin_transformer.py:607: error: Argument 2 to "VideoClassification" has incompatible type "tuple[int]"; expected "tuple[int, int]" [arg-type]
+ torchvision/models/video/swin_transformer.py:607: error: Argument "resize_size" to "VideoClassification" has incompatible type "tuple[int]"; expected "tuple[int, int]" [arg-type]
- torchvision/models/video/mvit.py:607: error: Argument 2 to "VideoClassification" has incompatible type "tuple[int]"; expected "tuple[int, int]" [arg-type]
+ torchvision/models/video/mvit.py:607: error: Argument "resize_size" to "VideoClassification" has incompatible type "tuple[int]"; expected "tuple[int, int]" [arg-type]
- torchvision/models/video/mvit.py:640: error: Argument 2 to "VideoClassification" has incompatible type "tuple[int]"; expected "tuple[int, int]" [arg-type]
+ torchvision/models/video/mvit.py:640: error: Argument "resize_size" to "VideoClassification" has incompatible type "tuple[int]"; expected "tuple[int, int]" [arg-type]
spack (https://github.com/spack/spack)
- lib/spack/spack/filesystem_view.py:133: error: Unexpected keyword argument "view" [call-arg]
+ lib/spack/spack/filesystem_view.py:183: error: Unexpected keyword argument "view" [call-arg]
kopf (https://github.com/nolar/kopf)
- kopf/_core/reactor/orchestration.py:42: error: Unexpected keyword argument "resource" for "__call__" of "WatchStreamProcessor" [call-arg]
+ kopf/_core/reactor/orchestration.py:246: error: Unexpected keyword argument "resource" for "__call__" of "WatchStreamProcessor" [call-arg]
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ pymongo/encryption.py:359: error: Incompatible types in assignment (expression has type "MongoClient[_DocumentTypeArg]", variable has type "MongoClient[_DocumentTypeArg]") [assignment]
graphql-core (https://github.com/graphql-python/graphql-core)
+ src/graphql/execution/async_iterables.py:34: error: Incompatible return value type (got "AsyncGenerator[T@__init__, None] | AsyncIterable[T@__init__]", expected "AsyncGenerator[T@__aenter__, None] | AsyncIterable[T@__aenter__]") [return-value]
jax (https://github.com/google/jax)
+ jax/_src/tree_util.py:964: error: Invalid index type "type[T@_register_keypaths]" for "dict[type[T], _RegistryWithKeypathsEntry]"; expected type "type[T@register_pytree_with_keys]" [index]
- jax/_src/scipy/signal.py:674: error: Argument 1 to "detrend" has incompatible type "Literal[True] | str"; expected "str" [arg-type]
+ jax/_src/scipy/signal.py:674: error: Argument "type" to "detrend" has incompatible type "Literal[True] | str"; expected "str" [arg-type]
- jax/experimental/pallas/ops/gpu/rms_norm.py:243: error: Argument 1 to "custom_vjp" has incompatible type "list[int]"; expected "tuple[int, ...]" [arg-type]
+ jax/experimental/pallas/ops/gpu/rms_norm.py:243: error: Argument "nondiff_argnums" to "custom_vjp" has incompatible type "list[int]"; expected "tuple[int, ...]" [arg-type]
- jax/experimental/pallas/ops/gpu/layer_norm.py:262: error: Argument 1 to "custom_vjp" has incompatible type "list[int]"; expected "tuple[int, ...]" [arg-type]
+ jax/experimental/pallas/ops/gpu/layer_norm.py:262: error: Argument "nondiff_argnums" to "custom_vjp" has incompatible type "list[int]"; expected "tuple[int, ...]" [arg-type]
- jax/experimental/pallas/ops/gpu/attention.py:149: error: Argument 1 to "custom_vjp" has incompatible type "list[int]"; expected "tuple[int, ...]" [arg-type]
+ jax/experimental/pallas/ops/gpu/attention.py:149: error: Argument "nondiff_argnums" to "custom_vjp" has incompatible type "list[int]"; expected "tuple[int, ...]" [arg-type]
- jax/experimental/pallas/ops/tpu/flash_attention.py:203: error: Argument 1 to "custom_vjp" has incompatible type "range"; expected "tuple[int, ...]" [arg-type]
+ jax/experimental/pallas/ops/tpu/flash_attention.py:203: error: Argument "nondiff_argnums" to "custom_vjp" has incompatible type "range"; expected "tuple[int, ...]" [arg-type]
- jax/experimental/pallas/ops/tpu/flash_attention.py:1088: error: Argument 1 to "_flash_attention_dkv_kernel" has incompatible type "int | None"; expected "int" [arg-type]
+ jax/experimental/pallas/ops/tpu/flash_attention.py:1088: error: Argument "block_q" to "_flash_attention_dkv_kernel" has incompatible type "int | None"; expected "int" [arg-type]
- jax/experimental/pallas/ops/tpu/flash_attention.py:1089: error: Argument 2 to "_flash_attention_dkv_kernel" has incompatible type "int | None"; expected "int" [arg-type]
+ jax/experimental/pallas/ops/tpu/flash_attention.py:1089: error: Argument "block_k" to "_flash_attention_dkv_kernel" has incompatible type "int | None"; expected "int" [arg-type]
- jax/experimental/pallas/ops/tpu/flash_attention.py:1437: error: Argument 4 to "_flash_attention_dq_kernel" has incompatible type "int | None"; expected "int" [arg-type]
+ jax/experimental/pallas/ops/tpu/flash_attention.py:1437: error: Argument "block_k" to "_flash_attention_dq_kernel" has incompatible type "int | None"; expected "int" [arg-type]
- jax/experimental/pallas/ops/tpu/paged_attention/paged_attention_kernel.py:618: error: Argument 5 has incompatible type "str | None"; expected "str" [arg-type]
+ jax/experimental/pallas/ops/tpu/paged_attention/paged_attention_kernel.py:618: error: Argument "megacore_mode" has incompatible type "str | None"; expected "str" [arg-type]
aiohttp (https://github.com/aio-libs/aiohttp)
- aiohttp/web_app.py:56:37: error: Unexpected keyword argument "handler" [call-arg]
+ aiohttp/web_app.py:386:50: error: Unexpected keyword argument "handler" [call-arg]
- aiohttp/web_app.py:56:37: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-call-arg for more info
+ aiohttp/web_app.py:386:50: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-call-arg for more info
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/defer.py:211: error: Argument 1 has incompatible type "_T@_callback"; expected "_T@__init__" [arg-type]
discord.py (https://github.com/Rapptz/discord.py)
- discord/ext/commands/hybrid.py:836: error: Incompatible return value type (got "Callable[[Callable[[CogT, ContextT, **P2], Coroutine[Any, Any, U]] | Callable[[ContextT, **P2], Coroutine[Any, Any, U]]], Any]", expected "Callable[[Callable[[CogT, ContextT, **P2], Coroutine[Any, Any, U]] | Callable[[ContextT, **P2], Coroutine[Any, Any, U]]], HybridCommand[CogT, P2, U]]") [return-value]
+ discord/ext/commands/hybrid.py:836: error: Incompatible return value type (got "Callable[[Callable[[CogT, ContextT@decorator, **P2], Coroutine[Any, Any, U@decorator]] | Callable[[ContextT@decorator, **P2], Coroutine[Any, Any, U@decorator]]], Any]", expected "Callable[[Callable[[CogT, ContextT, **P2], Coroutine[Any, Any, U]] | Callable[[ContextT, **P2], Coroutine[Any, Any, U]]], HybridCommand[CogT, P2, U]]") [return-value]
- discord/ext/commands/hybrid.py:860: error: Incompatible return value type (got "Callable[[Callable[[CogT, ContextT, **P2], Coroutine[Any, Any, U]] | Callable[[ContextT, **P2], Coroutine[Any, Any, U]]], Any]", expected "Callable[[Callable[[CogT, ContextT, **P2], Coroutine[Any, Any, U]] | Callable[[ContextT, **P2], Coroutine[Any, Any, U]]], HybridGroup[CogT, P2, U]]") [return-value]
+ discord/ext/commands/hybrid.py:860: error: Incompatible return value type (got "Callable[[Callable[[CogT, ContextT@decorator, **P2], Coroutine[Any, Any, U@decorator]] | Callable[[ContextT@decorator, **P2], Coroutine[Any, Any, U@decorator]]], Any]", expected "Callable[[Callable[[CogT, ContextT, **P2], Coroutine[Any, Any, U]] | Callable[[ContextT, **P2], Coroutine[Any, Any, U]]], HybridGroup[CogT, P2, U]]") [return-value]
- discord/ext/commands/bot.py:301: error: Incompatible return value type (got "Callable[[Callable[[Any, ContextT, **P], Coroutine[Any, Any, T]] | Callable[[ContextT, **P], Coroutine[Any, Any, T]]], Any]", expected "Callable[[Callable[[Any, ContextT, **P], Coroutine[Any, Any, T]] | Callable[[ContextT, **P], Coroutine[Any, Any, T]]], HybridCommand[Any, P, T]]") [return-value]
+ discord/ext/commands/bot.py:301: error: Incompatible return value type (got "Callable[[Callable[[Any, ContextT@decorator, **P], Coroutine[Any, Any, T@decorator]] | Callable[[ContextT@decorator, **P], Coroutine[Any, Any, T@decorator]]], Any]", expected "Callable[[Callable[[Any, ContextT, **P], Coroutine[Any, Any, T]] | Callable[[ContextT, **P], Coroutine[Any, Any, T]]], HybridCommand[Any, P, T]]") [return-value]
- discord/ext/commands/bot.py:325: error: Incompatible return value type (got "Callable[[Callable[[Any, ContextT, **P], Coroutine[Any, Any, T]] | Callable[[ContextT, **P], Coroutine[Any, Any, T]]], Any]", expected "Callable[[Callable[[Any, ContextT, **P], Coroutine[Any, Any, T]] | Callable[[ContextT, **P], Coroutine[Any, Any, T]]], HybridGroup[Any, P, T]]") [return-value]
+ discord/ext/commands/bot.py:325: error: Incompatible return value type (got "Callable[[Callable[[Any, ContextT@decorator, **P], Coroutine[Any, Any, T@decorator]] | Callable[[ContextT@decorator, **P], Coroutine[Any, Any, T@decorator]]], Any]", expected "Callable[[Callable[[Any, ContextT, **P], Coroutine[Any, Any, T]] | Callable[[ContextT, **P], Coroutine[Any, Any, T]]], HybridGroup[Any, P, T]]") [return-value]
ibis (https://github.com/ibis-project/ibis)
- ibis/expr/operations/tests/test_generic.py:145: error: Too many arguments for "Literal" [call-arg]
+ ibis/expr/operations/tests/test_generic.py:112: error: Too many arguments for "Literal" [call-arg]
- ibis/expr/operations/tests/test_generic.py:145: error: Unexpected keyword argument "name" for "Literal" [call-arg]
+ ibis/expr/operations/tests/test_generic.py:113: error: Unexpected keyword argument "name" for "Literal" [call-arg]
- ibis/expr/operations/tests/test_generic.py:145: error: "Literal" gets multiple values for keyword argument "dtype" [misc]
+ ibis/expr/operations/tests/test_generic.py:115: error: "Literal" gets multiple values for keyword argument "dtype" [misc]
bokeh (https://github.com/bokeh/bokeh)
- src/bokeh/driving.py:97:36: error: Argument 1 to "force" has incompatible type "Iterable[int]"; expected "Iterator[Any]" [arg-type]
+ src/bokeh/driving.py:97:36: error: Argument "sequence" to "force" has incompatible type "Iterable[int]"; expected "Iterator[Any]" [arg-type]
- src/bokeh/driving.py:116:36: error: Argument 1 to "force" has incompatible type "Iterable[float]"; expected "Iterator[Any]" [arg-type]
+ src/bokeh/driving.py:116:36: error: Argument "sequence" to "force" has incompatible type "Iterable[float]"; expected "Iterator[Any]" [arg-type]
- src/bokeh/driving.py:122:36: error: Argument 1 to "force" has incompatible type "Iterable[int]"; expected "Iterator[Any]" [arg-type]
+ src/bokeh/driving.py:122:36: error: Argument "sequence" to "force" has incompatible type "Iterable[int]"; expected "Iterator[Any]" [arg-type]
- src/bokeh/driving.py:154:36: error: Argument 1 to "force" has incompatible type "Iterable[float]"; expected "Iterator[Any]" [arg-type]
+ src/bokeh/driving.py:154:36: error: Argument "sequence" to "force" has incompatible type "Iterable[float]"; expected "Iterator[Any]" [arg-type]
- src/bokeh/driving.py:172:36: error: Argument 1 to "force" has incompatible type "Iterable[int]"; expected "Iterator[Any]" [arg-type]
+ src/bokeh/driving.py:172:36: error: Argument "sequence" to "force" has incompatible type "Iterable[int]"; expected "Iterator[Any]" [arg-type]
- src/bokeh/driving.py:191:36: error: Argument 1 to "force" has incompatible type "Iterable[float]"; expected "Iterator[Any]" [arg-type]
+ src/bokeh/driving.py:191:36: error: Argument "sequence" to "force" has incompatible type "Iterable[float]"; expected "Iterator[Any]" [arg-type]
hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/wrapper/_implementations.py:58: error: Too few arguments for "run" of "Context" [call-arg]
+ src/hydra_zen/wrapper/_implementations.py:414: error: Too few arguments for "run" of "Context" [call-arg]
- src/hydra_zen/wrapper/_implementations.py:563: error: Overloaded function implementation cannot satisfy signature 2 due to inconsistencies in how they use type variables [misc]
- src/hydra_zen/wrapper/_implementations.py:837: error: Argument "instantiation_wrapper" to "Zen" has incompatible type "Callable[[F2], F2] | None"; expected "Callable[[F2], F2] | None" [arg-type]
+ src/hydra_zen/wrapper/_implementations.py:837: error: Argument "instantiation_wrapper" to "Zen" has incompatible type "Callable[[F2@zen], F2@zen] | None"; expected "Callable[[F2@__init__], F2@__init__] | None" [arg-type]
- src/hydra_zen/wrapper/_implementations.py:851: error: Argument "instantiation_wrapper" to "Zen" has incompatible type "Callable[[F2], F2] | None"; expected "Callable[[F2], F2] | None" [arg-type]
+ src/hydra_zen/wrapper/_implementations.py:851: error: Argument "instantiation_wrapper" to "Zen" has incompatible type "Callable[[F2@zen], F2@zen] | None"; expected "Callable[[F2@__init__], F2@__init__] | None" [arg-type]
|
Fixes #16582
IMO this is long overdue. Currently, type variable IDs are 99% unique, but when they accidentally clash, it causes hard to debug issues. The implementation is generally straightforward, but it uncovered a whole bunch of unrelated bugs. Few notes:
checkexpr.py
to avoid ID clashes.partial
plugin were completely off (you can see examples inmypy_primer
where there were errors on empty lines etc).Instance
s. Note that I use a notationTypeVar@namespace
, which is a semantic equivalent of qualified name for type variables. For now, I shorten the namespace to only the last component, to make errors less verbose. We can reconsider this if it causes confusion.