---
title: a method has the same name than an attribute
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > a method has the same name than an attribute
---

# a method has the same name than an attribute

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site). ().
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `python-best-practices/method-hidden`

**Language:** Python

**Severity:** Warning

**Category:** Error Prone

## Description{% #description %}

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

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

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

    def bla(foo):
        pass

    def foo(self): # hidden by self.foo
        pass
```

```python
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{% #compliant-code-examples %}

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

    def bla(foo):
        pass

    def bar(self):
        pass
```

```python
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
```

```python
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
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 