Skip to content

Do not shadow user arguments in generated __new__ by @warnings.deprecated #132159

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

Closed
XuehaiPan opened this issue Apr 6, 2025 · 0 comments · Fixed by #132160
Closed

Do not shadow user arguments in generated __new__ by @warnings.deprecated #132159

XuehaiPan opened this issue Apr 6, 2025 · 0 comments · Fixed by #132160
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@XuehaiPan
Copy link
Contributor

XuehaiPan commented Apr 6, 2025

Bug report

Bug description:

Follow comment #132055 (comment)

from warnings import deprecated


@deprecated("MyMeta will go away soon")
class MyMeta(type):
    def __new__(mcs, name, bases, attrs, cls=None):
        return super().__new__(mcs, name, bases, attrs)


class Foo(metaclass=MyMeta, cls='haha'):
    pass

Output:

$ python3 test.py
Traceback (most recent call last):
  File "/Users/PanXuehai/Projects/cpython/test.py", line 10, in <module>
    class Foo(metaclass=MyMeta, cls='haha'):
        pass
TypeError: MyMeta.__new__() got multiple values for argument 'cls'

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Linked PRs

@XuehaiPan XuehaiPan added the type-bug An unexpected behavior, bug, or error label Apr 6, 2025
@picnixz picnixz added the stdlib Python modules in the Lib dir label Apr 6, 2025
JelleZijlstra pushed a commit that referenced this issue Apr 6, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Apr 6, 2025
…by `@warnings.deprecated` (pythonGH-132160)

(cherry picked from commit 7bb1e1a)

Co-authored-by: Xuehai Pan <[email protected]>
JelleZijlstra pushed a commit that referenced this issue Apr 6, 2025
… by `@warnings.deprecated` (GH-132160) (#132163)

gh-132159: Do not shadow user arguments in generated `__new__` by `@warnings.deprecated` (GH-132160)
(cherry picked from commit 7bb1e1a)

Co-authored-by: Xuehai Pan <[email protected]>
seehwan pushed a commit to seehwan/cpython that referenced this issue Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
2 participants