Skip to content

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

@cclauss

Description

@cclauss
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedReady for implementationbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions