-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
builtins.property not accepted as a valid type for subclassing #1529
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
Yeah, mypy probably only special-cases when the decorator is exactly
'builtins.property'. :-(
Do you have a work-around?
|
I thought that might be possible too, but changing to "builtins.property" also failed. The only place properties really seem to get handled is in SemanticAnalyzer.visit_decorator, but that never happens since this isn't a decorator. I did come up with a work-around of just implementing my own descriptor, which works fine and probably is what I should have done in the first place, I just found it an odd curiosity. |
Ah, I'm wrong. The cause seems simpler: In builtins.pyi, both versions, the
which makes it not a class. I'd entertain a patch to typeshed if you're interested. |
The original example now passes mypy, not sure however how useful the subclass can be (property is heavily special-cased in mypy), but at least the original bug is fixed, so closing this. |
mypy doesn't like it when I subclass the builtin class
property
:Running mypy 0.4.1 or 9e4cfc8 against that file, I get:
test.py:1: error: Invalid type "builtins.property"
But you totally can subclass property and build yourself a customized property decorator.
Looking at some debugger statements it seems like the type has been classified as not being an instance of TypeInfo. I'm afraid I can't offer a PR to fix this because I have no idea where that should be happening.
The text was updated successfully, but these errors were encountered: