-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Decide Type[C] vs. Callable #1670
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
Comments
Actually the test would be class C: pass
C1 = C # type: Type[C]
def f(a: Callable[[], C]) -> None: pass
f(C1) # E: Argument 1 to "f" has incompatible type Type[C]; expected Callable[[], C] and that currently errors. I do think it should work, though, since reveal_type(C1) # E: Revealed type is 'Type[T1670.C]'
reveal_type(C1()) # E: Revealed type is 'T1670.C' |
(Interestingly T = Type[C]
reveal_type(T) # Revealed type is 'Any' but it's not specific to |
The only valid "runtime" use for those is as type aliases -- they are
executed by the runtime and when used in PEP 3107 annotations available for
introspection using `types.get_type_hints()`. You can't instantiate them.
|
There is a related issue about type aliases having |
The code that was shown by @rwbarton earlier in this issue now passes type check. A simplified variation:
Presumably some recent PR fixed this issue and made It's ok to violate soundness, but in this case I think it can be avoided. My comment in #241 suggests an approach that I think would restore soundness. If that happens, Note that |
I think this issue is now fixed: class C: pass
C1 = C # type: Type[C]
def f(a: Callable[[], C]) -> None: pass
f(C1) # Correctly passes
def g(a: Callable[[], int]) -> None: pass
g(C1) # Correctly fails |
From #1569 (comment):
The current code seems to answer the first bullet with Yes:
has no errors. But what does that imply for the remaining two questions?
The text was updated successfully, but these errors were encountered: