-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
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
gh-101162: Forbid using issubclass
with GenericAlias
as the 1st arg
#103369
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks good to me. Strictly speaking, it's not backwards-compatible, but, as @serhiy-storchaka mentioned in the issue, it seems unlikely that anybody is passing a GenericAlias
object as the first argument of an issubclass()
call.
@Yhg1s, is it okay to make this change in 3.12? Or do we need a deprecation warning first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point I feel it's too late for 3.12: the feature freeze was extended only for pending PEPs, and this isn't one of them.
I feel we should go through a proper deprecation cycle here instead of just making the change. The behavior isn't completely unreasonable, so people may be relying on it.
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Yeap, but I guess it is fine for 3.13 :)
Hm, I don't quite agree. I think that this is just a regular bug (I think that it can even be backported). Here are my points:
>>> from typing import List
>>> issubclass(List[int], type)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: issubclass() arg 1 must be a class So, we don't ever teach users to rely on this historically.
>>> list[int].__bases__
(<class 'object'>,)
>>> issubclass(list[int], object)
True
>>> issubclass(list[int], type)
False Since most types just inherit from
If you find my arguments not convincing enough, I am always happy to do a deprecation warning. |
@serhiy-storchaka thanks for the review! Addressed. |
That you for your contribution @sobolevn. I do not think that a deprecation warning is needed here. This change could even be considered a bugfix and backported to 3.11 and 3.12, there there is no real need in this too. Blacklisting |
Now the implementation of
types.GenericAlias
andtyping._GenericAlias
is in line for this feature.