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

PLW0211: @staticmethod ; def __new__(cls, ...) disagrees with the Python docs #12930

Closed
cclauss opened this issue Aug 16, 2024 · 1 comment · Fixed by #12958
Closed

PLW0211: @staticmethod ; def __new__(cls, ...) disagrees with the Python docs #12930

cclauss opened this issue Aug 16, 2024 · 1 comment · Fixed by #12958
Labels
accepted Ready for implementation bug Something isn't working

Comments

@cclauss
Copy link
Contributor

cclauss commented Aug 16, 2024

ruff check --select=PLW0211 - <<EOF
class TestNew:
    @staticmethod
    def __new__(cls, title, *args, **kwargs):
        print(cls)
EOF

-:3:17: PLW0211 First argument of a static method should not be named cls

This contradicts https://docs.python.org/3/reference/datamodel.html#basic-customization which uses cls and states that __new__() is a static method.

PEP20 statement Explicit is better than implicit. suggests that @staticmethod should be allowed in this code.

@AlexWaygood
Copy link
Member

I think that's a somewhat extreme reading of PEP20! But yes, we should make an exception for __new__ here, which is obviously very special

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation bug Something isn't working
Projects
None yet
2 participants