Skip to content
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

reprlib.recursive_repr does not copy __type_params__ #109818

Closed
sobolevn opened this issue Sep 25, 2023 · 1 comment
Closed

reprlib.recursive_repr does not copy __type_params__ #109818

sobolevn opened this issue Sep 25, 2023 · 1 comment
Assignees
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Sep 25, 2023

Bug report

Repro:

>>> from reprlib import recursive_repr
>>> 
>>> class My:
...    @recursive_repr()
...    def __repr__[T](self, converter: T | None = None): ...
... 
>>> My().__repr__.__type_params__
()

This happens because recursive_repr does not use @wraps, but reinvents it:

cpython/Lib/reprlib.py

Lines 26 to 33 in f2eaa92

# Can't use functools.wraps() here because of bootstrap issues
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.__wrapped__ = user_function
return wrapper

And __type_params__ was added in #104600

Linked PRs

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir 3.12 bugs and security fixes 3.13 bugs and security fixes labels Sep 25, 2023
@sobolevn sobolevn self-assigned this Sep 25, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Sep 25, 2023
JelleZijlstra pushed a commit to JelleZijlstra/cpython that referenced this issue Sep 28, 2023
…s__` (pythonGH-109819).

(cherry picked from commit f65f9e8)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
csm10495 pushed a commit to csm10495/cpython that referenced this issue Sep 29, 2023
Yhg1s pushed a commit that referenced this issue Oct 2, 2023
#109999)

[3.12] gh-109818: `reprlib.recursive_repr` copies `__type_params__` (GH-109819).
(cherry picked from commit f65f9e8)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@hugovk
Copy link
Member

hugovk commented Nov 9, 2023

Thanks for the issue and PRs!

Little reminder to close issues when the PRs are merged :)

@hugovk hugovk closed this as completed Nov 9, 2023
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants