We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
type[T]
From this discussion at @microsoft/pyright:
(playground) @dataclass(kw_only = True) class User: id: int name: str class HasCls[**P, T](Protocol): cls: Callable[P, T] class Repository[T]: cls: type[T] def __init__(self, cls: type[T]) -> None: ... def create[**P](self: HasCls[P, T], *args: P.args, **kwargs: P.kwargs) -> T: ... class UserDatabase(Repository[User]): def __init__(self) -> None: ... Expected: user = UserDatabase().create(id = 1, name = 'foo') # fine reveal_type(UserDatabase().create) # (*, id: int, name: str) -> User reveal_type(user) # User
(playground)
@dataclass(kw_only = True) class User: id: int name: str class HasCls[**P, T](Protocol): cls: Callable[P, T] class Repository[T]: cls: type[T] def __init__(self, cls: type[T]) -> None: ... def create[**P](self: HasCls[P, T], *args: P.args, **kwargs: P.kwargs) -> T: ... class UserDatabase(Repository[User]): def __init__(self) -> None: ...
Expected:
user = UserDatabase().create(id = 1, name = 'foo') # fine reveal_type(UserDatabase().create) # (*, id: int, name: str) -> User reveal_type(user) # User
Actual:
# error: Invalid self argument "UserDatabase" to attribute function "create" with type "Callable[[HasCls[P, T], **P], T]" [misc] user = UserDatabase().create(id = 1, name = 'foo') reveal_type(UserDatabase().create) # (*args: Never, **kwargs: Never) -> User reveal_type(user) # User
The pattern above is supported by Pyright, if not for a bug that this snippet helped discovering (which has since been fixed).
The text was updated successfully, but these errors were encountered:
No branches or pull requests
From this discussion at @microsoft/pyright:
Actual:
The pattern above is supported by Pyright, if not for a bug that this snippet helped discovering (which has since been fixed).
The text was updated successfully, but these errors were encountered: