bpo-41905: added abc.update_abstractmethods#22485
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
Sorry, something went wrong.
ericvsmith
left a comment
There was a problem hiding this comment.
Although I'm no expert on ABC's, this looks good to me, with a few noted tiny changes. I'll do some more research before signing off on this, though.
My only real concern is that dataclasses now imports abc. We've jumped through hoops to make dataclasses not import typing, because it's slow to import. I don't know if abc brings the same issues, but I'll try to do some investigating. The trick it uses for typing is to check if 'typing' is in sys.modules before checking for typing.<somthing_or_other>. I'm not sure such trickery is warranted here. Probably not, since just starting the REPL looks like it imports abc (but not typing).
Sorry, something went wrong.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Sorry, something went wrong.
|
I have made the requested changes; please review again |
Sorry, something went wrong.
|
Thanks for making the requested changes! @ericvsmith: please review the changes made to this pull request. |
Sorry, something went wrong.
|
Since |
Sorry, something went wrong.
Change looks good. Thanks. |
Sorry, something went wrong.
If this does prove to be an issue, then we can change the |
Sorry, something went wrong.
gvanrossum
left a comment
There was a problem hiding this comment.
I just don't care enough about the purely hypothetical scenario you're describing to want to complicate this function. The automatic solution also has its problems (to begin, it would require C code).
Sorry, something went wrong.
|
Just noted this:
I looked into this, dataclasses already imports functools which already imports abc, so there's no new module being loaded. Also, abc.py is pretty compact and backed by C code -- most of the Python code is in So I don't think there's a worry. @ericvsmith, all your other comments seem to have been taken care of this -- can you sign off? (Unless you want to jump into the debate about subclasses.) |
Sorry, something went wrong.
|
@gvanrossum: Agreed about importing abc. I'll let you and the others work out the subclass issue. |
Sorry, something went wrong.
Co-authored-by: Guido van Rossum <guido@python.org>
Co-authored-by: Guido van Rossum <guido@python.org>
Co-authored-by: Guido van Rossum <guido@python.org>
|
Of course, I defer judgement to the dev team, but I'd be remiss if I didn't reflect the implications of this behavior: When this behavior is implemented, it will effectively split all class decorators into one of three categories:
An important consequence is, that decorators can only be reliably stacked on top of each other only if they are of the same category. And while Of course, the mere existence of a decorator of the third category is a case so far fetched that I doubt it even exists across all python code. This is a valid reason to discount it, but the implication is that if were to ever exist, it could not be used with virtually any other decorator. |
Sorry, something went wrong.
Importing abc is not a concern: it will already be imported via functools.
gvanrossum
left a comment
There was a problem hiding this comment.
You can consider us amply warned.
Sorry, something went wrong.
A very pedantic one, which should not block this PR being merged. The doc says "It does not update any subclasses", but no test asserts this. |
Sorry, something went wrong.
|
Thanks! All merged. |
Sorry, something went wrong.
* origin/master: (147 commits) Fix the attribute names in the docstring of GenericAlias (pythonGH-22594) bpo-39337: Add a test case for normalizing of codec names (pythonGH-19069) bpo-41557: Update Windows installer to use SQLite 3.33.0 (pythonGH-21960) bpo-41976: Fix the fallback to gcc of ctypes.util.find_library when using gcc>9 (pythonGH-22598) bpo-41306: Allow scale value to not be rounded (pythonGH-21715) bpo-41970: Avoid test failure in test_lib2to3 if the module is already imported (pythonGH-22595) bpo-41376: Fix the documentation of `site.getusersitepackages()` (pythonGH-21602) Revert "bpo-26680: Incorporate is_integer in all built-in and standard library numeric types (pythonGH-6121)" (pythonGH-22584) bpo-41923: PEP 613: Add TypeAlias to typing module (python#22532) Fix comment about PyObject_IsTrue. (pythonGH-22343) bpo-38605: Make 'from __future__ import annotations' the default (pythonGH-20434) bpo-41905: Add abc.update_abstractmethods() (pythonGH-22485) bpo-41944: No longer call eval() on content received via HTTP in the UnicodeNames tests (pythonGH-22575) bpo-41944: No longer call eval() on content received via HTTP in the CJK codec tests (pythonGH-22566) Post 3.10.0a1 Python 3.10.0a1 bpo-41584: clarify when the reflected method of a binary arithemtic operator is called (python#22505) bpo-41939: Fix test_site.test_license_exists_at_url() (python#22559) bpo-41774: Tweak new programming FAQ entry (pythonGH-22562) bpo-41936. Remove macros Py_ALLOW_RECURSION/Py_END_ALLOW_RECURSION (pythonGH-22552) ...
This function recomputes `cls.__abstractmethods__`. Also update `@dataclass` to use it.
relevant python-ideas thread: https://mail.python.org/archives/list/python-ideas@python.org/thread/6BNJ3YSEBPHEPGXSAZGBW3TJ64ZGZIHE/
https://bugs.python.org/issue41905