Skip to content
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

Protocols don't support descriptors #5481

Open
ilevkivskyi opened this issue Aug 14, 2018 · 6 comments
Open

Protocols don't support descriptors #5481

ilevkivskyi opened this issue Aug 14, 2018 · 6 comments
Labels

Comments

@ilevkivskyi
Copy link
Member

ilevkivskyi commented Aug 14, 2018

Consider this code:

class Descr:
    def __get__(self, inst: Any, owner: Any) -> int: ...

class Proto(Protocol):
    x: int

class C:
    x = Descr()

a: Proto = C()

I think it should be allowed. This can be done by simply re-using the logic in analyze_member_access in checkmember.py, see also #5136.

@bryanforbes
Copy link
Contributor

This will be fixed when #3832 is complete

@ilevkivskyi
Copy link
Member Author

This appeared again in dropbox/sqlalchemy-stubs#134

@ckarnell
Copy link
Contributor

Can you tell me exactly where in the code the duplication is happening WRT Protocols, so I can try to piece together some understanding and look into fixing it? I'm looking myself but it's not immediately obvious, and I'm unfamiliar with the codebase.

@ilevkivskyi
Copy link
Member Author

Just to set realistic expectations: it is unlikely anyone beyond core team can fix this. But anyway, the problematic logic duplication is between is_protocol_implementation()/find_member() in subtypes.py and analyze_instance_member_access() in checkmember.py.

@ckarnell
Copy link
Contributor

Got it, makes sense. I might take a peek anyway just out of curiosity.

@sobolevn
Copy link
Member

This was raised once again in django-stubs repo: typeddjango/django-stubs#651

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

No branches or pull requests

4 participants