-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Being unable to specify the API for instantiating an object is a deleterious restriction for Protocols #110788
Comments
Can you give some specific examples of code you think should work but doesn't? You may be interested in #31628 (released in 3.11 and 3.12) that preserves |
@JelleZijlstra I thought I was going insane, because I had documentation generated from a Protocol that somehow preserved the My specific case is the interface for encoding state deltas in delta-state CRDTs. I have a library which implements 12 of them (crdts), and I am preparing to push an update. I encountered this strange behavior while updating the documentation, when I noticed that the |
So is there still a change that you're asking us to make? |
It is kind of weird for a package to have differing behavior between 3.10 and 3.11. Is there a way to patch this specific change into 3.10, or does that go against policy? |
We made this change only on 3.10 because we judged it too risky for a bugfix. (If we fixed it in 3.10, earlier bugfix versions of 3.10 would behave differently than later ones, which is even more likely to lead to confusion.) Now, 3.10 is in security fix-only mode, so it's definitely too late to make the change in 3.10. |
@k98kurz, if you'd like to have the py311 behaviour on py310, you can use the |
(Should be closed as completed as we did indeed implement the proposed change.) |
It makes no sense to be unable to specify the interface for instantiating a class object. The only way around this at the moment is to specify a class method that serves the literal same purpose as the
__init__
method, then relying upon it instead of the normal mechanism for object instantiation.This is one of the poorest design decisions in CPython in my opinion. It breaks introspection tools that seek to document the required
__init__
API, and it breaks even the concept of checking if the required__init__
API is followed. As I said, the only way around this is to create a new class method that merely replicates what the built-in__init__
method is supposed to do.cpython/Lib/typing.py
Line 1430 in b4e48a4
If there is some justification for this frustrating antipattern, please let me know. I do not see anything about this in PEP-544, though I only skimmed it looking for an answer and did not study it thoroughly.
The text was updated successfully, but these errors were encountered: