Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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-123777: Allow
__orig_class__
to be accessed in__init__
#123878gh-123777: Allow
__orig_class__
to be accessed in__init__
#123878Changes from 2 commits
e6a84cc
8cc02fe
0084601
19c0b1e
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
This doesn't seem to do what you want it to do:
This PR doesn't include tests; to get it merged we'll definitely need tests.
I'm also not convinced we should change this at all, since it feels like a risky change at this point.
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.
You may want to compare against
object.__new__
instead, but that still doesn't directly check for "Python types", and in any case I'm not sure it's a good idea to branch on whether it's a Python type.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.
Yeah, Alex had the same concern, I just pushed a better fix instead of
type.__new__
.Very much agreeing there, but there does seem to be some demand from the typing users. If this causes a regression somewhere, we could always roll back the changes!
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.
If we release this in 3.14.0, then backward compatibility will again mean we're stuck with the change. CPython is deep enough in the stack that we can't afford to just go back and forth.
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.
Oh yeah, that sounds like the right approach, my bad!
Hmm, maybe we should bring this to Discourse.
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.
Just because there's a problem doesn't mean that this is the best fix.
__orig_class__
is completely undocumented and the last time we discussed potentially documenting it we decided not to because it sometimes has a counterintuitive value. For other typing-specific dunders our approach has generally been to expose public introspection helpers so that we're easily able to refactor internals later without breaking any public interface (e.g.get_protocol_members()
,types.get_original_bases
, etc.).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.
There can be C types with
__init__
as well.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.
As in, there are C types that might want to access their own
__orig_class__
?