Este producto no es compatible con el sitio Datadog seleccionado. ().
Esta página aún no está disponible en español. Estamos trabajando en su traducción.
Si tienes alguna pregunta o comentario sobre nuestro actual proyecto de traducción, no dudes en ponerte en contacto con nosotros.

Metadata

ID: python-best-practices/method-hidden

Language: Python

Severity: Warning

Category: Error Prone

Description

Make sure that class attribute and class methods have a unique name without any collision.

Non-Compliant Code Examples

class MyClass:
    def __init__(self, something):
        self.foo = something

    def bla(foo):
        pass

    def foo(self): # hidden by self.foo
        pass
class Config:
    def __init__(self, value):
        self.threshold = value
        self.max_val = 100

    @property
    def threshold(self) -> int:
        return self._threshold

    def max_val(self):  # hidden by self.max_val, not a property
        pass

Compliant Code Examples

class MyClass:
    def __init__(self, something):
        self.foo = something

    def bla(foo):
        pass

    def bar(self):
        pass
from abc import abstractmethod

class AbstractBase:
    def __init__(self):
        self.value = 0

    @property
    @abstractmethod
    def value(self):
        pass

    @value.setter
    @abstractmethod
    def value(self, v):
        pass
class Counter:
    def __init__(self, start):
        self.count = start
        self.max_value = 100

    @property
    def count(self) -> int:
        return self._count

    @count.setter
    def count(self, val: int) -> None:
        self._count = val

    def reset(self):
        self.count = 0
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Integraciones sin problemas. Prueba Datadog Code Security