Open
Description
Current problem
As of version 1.0, Mypy supports the Self
type. So, I would like a checker that suggests using Self
where it is possible.
Desired solution
This means checking the return annotations for class methods and seeing if any can be Self
.
It's not as simple as checking whether the return annotation is the same as the class. I don't understand the details exactly, but I think the method has to return the object itself, i.e. self
. In this example, the increment
method is a candidate for using Self
, but the copy
method is not:
from dataclasses import dataclass
@dataclass
class Counter:
count: int = 0
def increment(self) -> Counter: # consider-using-self
self.count += 1
return self
def copy(self) -> Counter: # not Self
return Counter(self.count)