> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Instance Method First Parameter Should Be `self`

#### Sourcery refactoring id: `instance-method-first-arg-name`

#### Description:

Suggests that instance methods should rename their first parameter to `self`.

#### Before:

```python
class Chicken:
    def lay_egg(this, coop):
        with this.enter_coop(coop):
            coop.eggs.add(Egg(this.dna))
```

#### After:

```python
class Chicken:
    def lay_egg(self, coop):
        with self.enter_coop(coop):
            coop.eggs.add(Egg(self.dna))
```

#### Explanation:

This is both a very strong convention in Python and an explicit entry in
[PEP-8](https://peps.python.org/pep-0008/#function-and-method-arguments).
Adhering to it improves code consistency and makes it easier for developers to
understand the intention of your code.

Note that we do not suggest this where there are decorators present, since these
can override the behaviour, meaning that `self` is not the correct name.

See also: [`class-method-first-arg-name`](/reference/refactorings/python/class-method-first-arg-name/)
