gh-101162: Forbid using issubclass with GenericAlias as the 1st arg#103369
gh-101162: Forbid using issubclass with GenericAlias as the 1st arg#103369serhiy-storchaka merged 4 commits intopython:mainfrom
issubclass with GenericAlias as the 1st arg#103369Conversation
AlexWaygood
left a comment
There was a problem hiding this comment.
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?
JelleZijlstra
left a comment
There was a problem hiding this comment.
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 classSo, 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)
FalseSince 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.GenericAliasandtyping._GenericAliasis in line for this feature.