-
Notifications
You must be signed in to change notification settings - Fork 17
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
Incorporate typing_extensions
into type checkers
#19
Comments
One important clarification: Using But for As a workaround we can use the class name explicitly. For example: class S:
@classmethod
def make(cls) -> S:
return cls()
class T(S):
pass
def print_t(t: T) -> None:
print(t)
print_t(T.make()) This should fail a type checking, because from typing_extensions import Self
class S:
@classmethod
def make(cls) -> Self: # <------
return cls()
class T(S):
pass
def print_t(t: T) -> None:
print(t)
print_t(T.make()) Note: this is untested because |
Some other important clarifications:
|
We already have |
What's needed?
Type annotations in some cases are limited and thus it would be good to enhance them with what the
typing-extensions
package has to offer.One example of this would be
@classmethod
, which always usescls
argument as the first argument. Ideally, we would annotate it with theSelf
type from thetyping-extensions
package.Proposed solution
Use
typing-extensions
package to enhance type annotations.Use cases
This can be applied to
@classmethod
s and perhaps other functions used as decorators. One apparent case where we could use better type checking is the@actor
decorator, which decorates classes at runtime making it impossible forpylint
to verify if attributes / methods are defined on the decorated class.Alternatives and workarounds
In case of
@classmethod
, we an omit the type annotation for thecls
argument and it still passes type checking.Otherwise, we have to explicitly tell type checkers
pylint
and/ormypy
that a particular line should be ignored, because there is no correct type annotation available.Additional context
No response
The text was updated successfully, but these errors were encountered: