Open
Description
# pylint: disable=no-self-use
class Parent:
def func(self) -> int | None:
return None
def serialize(self) -> str:
x = self.func() # assignment-from-none
return f"Result: {x if x else ''}"
class Child(Parent):
def func(self) -> int:
return 42
In the example above, assignment-from-none
is emitted on a method call even though func()
could be overwritten and not return None
.
Proposal
Limit the assignment-from-none
check to functions. Methods should only be considered if marked with @typing.final
. It might also work to check the return type itself to see if it's only -> None
.
Reason
We can't reliably determine if a method is ever overwritten and thus return something else then None
.