do not use self as parameter for static methods

Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Metadata

ID: python-best-practices/static-method-no-self

Language: Python

Severity: Error

Category: Best Practices

Description

A static method makes no use of an instance. Therefore, the self argument is not needed nor useful and should not be used.

Non-Compliant Code Examples

class Foo:
  @staticmethod
  def foo(self, bar):  # no need to use the self argument with a @staticmethod
     pass

Compliant Code Examples

class Foo:
  @staticmethod
  def foo(bar):
     pass
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis