Conversation
This comment has been minimized.
This comment has been minimized.
|
I think I've broken mypy primer, will fix |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
This is a great improvement! There are still a few things that don't work, like this one: # flags: --warn-unreachable
from typing import Optional, TypeVar
T = TypeVar("T", bound=Optional[int]) # `Union[None, int]` gives the same result
def foo(v: T) -> T:
if v is None:
return v # E: Statement is unreachable [unreachable]
return vbut that's maybe a different problem. |
|
Might be nice to somehow indicate the updated upper bound in the repr |
|
I've added |
|
Surprisingly all mypy_primer results are expected :) I'm making this do slightly more than originally planned by changing how narrowed TypeVars are stringified. |
f195e01 to
61b71e9
Compare
This comment has been minimized.
This comment has been minimized.
61b71e9 to
b84e3f8
Compare
This comment has been minimized.
This comment has been minimized.
|
@JelleZijlstra This implements the first option I've outlined in #15151 (comment), can take a look? |
|
I think I'll pass on this one, sorry. I'm mostly focusing my open-source time on projects other than mypy. |
|
@ilevkivskyi What do you think? |
|
Diff from mypy_primer, showing the effect of this PR on open source code: mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/coretypes/serializable.py:186: error: Unused "type: ignore" comment [unused-ignore]
steam.py (https://github.com/Gobot1234/steam.py)
- steam/ext/commands/commands.py:287: error: Argument 1 to "append" of "list" has incompatible type "Command[Any, Any, Any]"; expected "Self" [arg-type]
- steam/ext/commands/commands.py:940: error: Incompatible return value type (got "Command[Any, Any, Any] | MaybeCommandT", expected "MaybeBool | MaybeCommandT") [return-value]
mypy (https://github.com/python/mypy)
+ mypy/typeops.py:342: error: Incompatible types in assignment (expression has type "CallableType", variable has type "F") [assignment]
pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ tests/__init__.py:30: error: Unused "type: ignore" comment [unused-ignore]
+ tests/__init__.py:44: error: Unused "type: ignore" comment [unused-ignore]
|
|
I propose to close this in favor of #19183 that offers a different approach. |
Fixes #15151.
When
isinstancenarrows a TypeVar, it should narrow it to a bounded TypeVar rather than to an Instance, so it could keep functioning as that TypeVar.