-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Binding an abc to TypeVar loses abstract class check #1830
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
See #1831 for a proposed change that could perhaps address this problem as well. |
Could we perhaps make it so that if you have |
Support for Line 31 now fails
Line 44 also fails: ja2 = new_user2(User) # E: Only concrete class can be given where "Type[User]" is expected No error is reported for new_user2 def new_user2(user_class):
# type: (Type[User]) -> User
user = user_class()
return user Looks like this bug has been resolved. Am I wrong? |
Yeah, this has been fixed -- I recall seeing a PR, but I don't recall the details. If you want to be really thorough you can use |
I was looking at the docstring of Type and noticed that it used a TypeVar for the argument. I wasn't using TypeVars so I started adding them to my code. But then I noticed I was getting fewer errors and mypy was not warning me about creating abstract base classes. Here's my simplified code:
(This was in python 2)
I can't tell what's better. It's annoying that
(Type[User]) -> User
wouldn't work. But I sort of understand that it can't guarantee to work. What I've done to work around this is have user_class instead be a function that returns a User.The text was updated successfully, but these errors were encountered: