Skip to content

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

Closed
beckjake opened this issue May 13, 2016 · 4 comments
Closed

builtins.property not accepted as a valid type for subclassing #1529

beckjake opened this issue May 13, 2016 · 4 comments

Comments

@beckjake
Copy link
Contributor

mypy doesn't like it when I subclass the builtin class property:

class blah(property):
    pass

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.

@gvanrossum
Copy link
Member

gvanrossum commented May 13, 2016 via email

@beckjake
Copy link
Contributor Author

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.

@gvanrossum
Copy link
Member

Ah, I'm wrong. The cause seems simpler: In builtins.pyi, both versions, the
definition of property is

property = object()

which makes it not a class.

I'd entertain a patch to typeshed if you're interested.

@ilevkivskyi
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants