typing icon indicating copy to clipboard operation
typing copied to clipboard

Allow `issubclass` for protocols with class variables

Open vnmabus opened this issue 4 years ago • 8 comments

Currently issubclass cannot be used for runtime_checkable protocols with data members, because those attributes could be set in __init__. I propose to relax this restriction to allow protocols with ClassVar members, as those should be present in the class definition.

vnmabus avatar Jul 07 '21 11:07 vnmabus

That looks reasonable. Could you submit a PR? Does this need changing in mypy too?

gvanrossum avatar Jul 07 '21 14:07 gvanrossum

I do not think this needs to change in mypy, as the problem is using issubclass at runtime. I am also not familiar with the codebase, so I do not know how to made the PR.

vnmabus avatar Jul 07 '21 14:07 vnmabus

Maybe a project for @Fidget-Spinner? This would be a new feature in 3.11.

gvanrossum avatar Jul 07 '21 14:07 gvanrossum

Sure, I'll take a shot at this. Currently I'm a little busy with other things in CPython, so I might not be able to work on this immediately.

We're not in a hurry (yet), 3.11's first alpha is in October 2021, and beta freeze in April 2022.

Fidget-Spinner avatar Jul 07 '21 14:07 Fidget-Spinner

@gvanrossum @Fidget-Spinner I can help with this feature if you need help. I am familiar with typing module so I think it won't be a problem to implement this feature.

uriyyo avatar Jul 30 '21 12:07 uriyyo

@uriyyo sorry, I'm working on this. I will tell you if I need any help.

Fidget-Spinner avatar Jul 30 '21 13:07 Fidget-Spinner

@Fidget-Spinner Great, I am waiting to see your implementation)

uriyyo avatar Jul 30 '21 13:07 uriyyo

PR for CPython is open at https://github.com/python/cpython/pull/27883. Once that is merged, we can downstream it to typing_extensions.

Fidget-Spinner avatar Aug 22 '21 09:08 Fidget-Spinner