-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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-109653: Just import recursive_repr
in dataclasses
#109822
Conversation
The windows failure is known and unrelated: #109739 |
I don't think this change is worth making. It seems mostly like code churn: there's no actual problem being solved. |
Is there a difference if the A |
@AA-Turner it makes no difference, because
But, it still does not improve the import time:
I also tried to defer |
@sobolevn I get similar numbers (scale-wise) from pyperf but they don't match with other timings I've done.
Which lines up roughly with the timings I get from
From previous experiments mentioned in #109653 (comment) I would expect deferring Slightly more directly related, and also mentioned in #109653 (comment) the definition of Footnotes
|
A change in the other direction (per diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 84f8d68ce0..8579f6d605 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -4,7 +4,6 @@
import types
import inspect
import keyword
-import functools
import itertools
import abc
import _thread
@@ -252,7 +251,6 @@ def _recursive_repr(user_function):
# call.
repr_running = set()
- @functools.wraps(user_function)
def wrapper(self):
key = id(self), _thread.get_ident()
if key in repr_running:
@@ -263,6 +261,15 @@ def wrapper(self):
finally:
repr_running.discard(key)
return result
+
+ wrapper.__module__ = getattr(user_function, '__module__')
+ wrapper.__doc__ = getattr(user_function, '__doc__')
+ wrapper.__name__ = getattr(user_function, '__name__')
+ wrapper.__qualname__ = getattr(user_function, '__qualname__')
+ wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
+ wrapper.__type_params__ = getattr(user_function, '__type_params__', ())
+ wrapper.__wrapped__ = user_function
+
return wrapper
class InitVar: A |
@AA-Turner we still have |
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.
boilerplate code that can go out of sync with the reprlib.recursive_repr (it happened before #109819)
IMO, this is a good reason to merge this PR.
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 long as there's not a performance regression due to importing reprlib, I'm okay with this. I have not checked the performance.
You're already importing |
Agreed that reprlib is already imported (checked with 3.11). |
Import time is unchanged. Before:
After:
But, we now drop two dependencies:
functools
and_thread
and add just one:reprlib
https://github.com/python/cpython/blame/f2eaa92b0cc5a37a9e6010c7c6f5ad1a230ea49b/Lib/dataclasses.py#L248-L266
It was strange to have
But import two other heavier modules. The most interesting part is that
functools
always importsreprlib
inside. See #109653 (comment)