Closed simensol closed 6 months ago
When my custom managers went from untyped:
objects = GroupManager()
to typed:
objects: ClassVar[GroupManager] = GroupManager()
classmethods returning Self, e.g.:
Self
@classmethod def create( cls, name: str ) -> Self: return cls.objects.create( name=name, )
started to raise the following linting error:
Expression of type "Group" cannot be assigned to return type "Self@Group" Type "Group" cannot be assigned to type "Self@Group" Pylance(reportReturnType)
I fixed this by returning "Group" instead:
"Group"
@classmethod def create( cls, name: str ) -> "Group": return cls.objects.create( name=name, )
However, according to PEP 673, a classmethod should be able to return Self.
Hmm is this a pyright issue?
Correct types solved the issue. See https://github.com/microsoft/pyright/issues/7251#issuecomment-1940625332 for solution.
When my custom managers went from untyped:
to typed:
classmethods returning
Self
, e.g.:started to raise the following linting error:
I fixed this by returning
"Group"
instead:However, according to PEP 673, a classmethod should be able to return
Self
.