-
-
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
TypeVar
not narrowed when using isinstance
or issubclass
on final
classes
#12163
Labels
bug
mypy got something wrong
topic-final
PEP 591
topic-type-narrowing
Conditional type narrowing / binder
topic-type-variables
Comments
DetachHead
changed the title
generic not narrowed when using
generic not narrowed when using Feb 10, 2022
subclasscheck
on type
of genericisinstance
or issubclass
DetachHead
changed the title
generic not narrowed when using
Feb 11, 2022
isinstance
or issubclass
TypeVar
not narrowed when using isinstance
or issubclass
DetachHead
changed the title
Feb 11, 2022
TypeVar
not narrowed when using isinstance
or issubclass
TypeVar
not narrowed when using isinstance
or issubclass
on final
classes
Here is the minified version: from typing import final
@final
class A: ...
class B: ...
a: A
assert isinstance(a, B)
reveal_type(a) # note: Revealed type is "__main__.<subclass of "A" and "B">"
print("hi") # no unreachable error |
AlexWaygood
added
topic-final
PEP 591
topic-type-narrowing
Conditional type narrowing / binder
labels
Mar 24, 2022
This issue is probably the same reason for this error here? import typing
class A: ...
@typing.final
class AA(A): ...
T = typing.TypeVar("T", bound=A)
def test(x: T) -> T:
if isinstance(x, AA):
return AA() # error: Incompatible return value type (got "AA", expected "T")
raise NotImplementedError() The expected return type within the Using |
hauntsaninja
pushed a commit
that referenced
this issue
Dec 4, 2023
…16330) Fixes #15148 I think it also fixes the [initial bug](#12163 (comment)) reported in #12163 (this is why I added a TypeVar test case) but not [this bug](#12163 (comment)) reported later in the same issue.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
mypy got something wrong
topic-final
PEP 591
topic-type-narrowing
Conditional type narrowing / binder
topic-type-variables
https://mypy-play.net/?mypy=master&python=3.10&flags=show-error-codes%2Callow-redefinition%2Cstrict%2Ccheck-untyped-defs%2Cdisallow-any-decorated%2Cdisallow-any-expr%2Cdisallow-any-explicit%2Cdisallow-any-generics%2Cdisallow-any-unimported%2Cdisallow-incomplete-defs%2Cdisallow-subclassing-any%2Cdisallow-untyped-calls%2Cdisallow-untyped-decorators%2Cdisallow-untyped-defs%2Cno-implicit-optional%2Cno-implicit-reexport%2Cstrict-equality%2Cwarn-incomplete-stub%2Cwarn-redundant-casts%2Cwarn-return-any%2Cwarn-unreachable%2Cwarn-unused-configs%2Cwarn-unused-ignores&gist=43b6f21a9c890c7da5e41e2591b321b0
(the error messages are wrong due to #11536)
The text was updated successfully, but these errors were encountered: