-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
Odd types.get_original_bases() behavior for classes with generic bases but no type arguments #107576
Comments
Agree that this is unfortunate and we should fix it, preferably before 3.12.0 final, as this is a new function. cc @Yhg1s and @Gobot1234 |
The proposed fix of checking |
RC1 is still pending another fix, so if we can get a simple fix for this in quickly, that would be good :) (The 3.12 ranch is locked to anyone but me, so send PRs my way for the backport merge). |
@chrisbouchard, thanks for testing with the betas! It's really helpful to get these bug reports early :D |
@AlexWaygood I was very excited to try out Thank you all for being so responsive! This was really awesome 👍 |
#107584) Co-authored-by: Chris Bouchard <chris@upliftinglemma.net> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
…_bases` (pythonGH-107584) (cherry picked from commit ed4a978) Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com> Co-authored-by: Chris Bouchard <chris@upliftinglemma.net> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
…l_bases` (GH-107584) (#107592) gh-107576: Ensure `__orig_bases__` are our own in `get_original_bases` (GH-107584) (cherry picked from commit ed4a978) Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com> Co-authored-by: Chris Bouchard <chris@upliftinglemma.net> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Fixed and backported; thanks again everybody! |
Bug report
Checklist
A clear and concise description of the bug
(I originally posted about this on python-list a little over a week ago, but didn't get any replies.) I was playing around with 3.12.0b4 recently and noticed an odd (to me, at least) behavior with
types.get_original_bases()
.In summary,
types.get_original_bases(Example)
is returning the original base types forFirst
, rather than its own.I believe this happens because
__orig_bases__
is only set when one or more of a generic type's bases are not types. In this case both bases are types, soExample
doesn't get its own__orig_bases__
. Then whentypes.get_original_bases()
tries to get__orig_bases__
onExample
, it searches the MRO and finds__orig_bases__
onFirst
.The same thing also happens if all the bases are “bare” generic types.
I'm not entirely clear if this is a bug, or an intended (but unfortunate) behavior. I would personally expect
types.get_original_bases()
to check if the type has its own__orig_bases__
attribute, and to fall back to__bases__
otherwise.For example, the way it works currently makes it unnecessarily difficult to write a function that recurses down a type's inheritance tree inspecting the original bases—I currently have to work around this behavior via hacks like checking
"__orig_bases__" in cls.__dict__
orany(types.get_original_bases(cls) == types.get_original_bases(base) for base in cls.__bases__)
. (Unless I'm missing some simpler solution.)Is this something that could (should?) be addressed before 3.12 lands?
Your environment
Linked PRs
__orig_bases__
are our own inget_original_bases
#107584__orig_bases__
are our own inget_original_bases
(GH-107584) #107592The text was updated successfully, but these errors were encountered: