3

For the following function

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Node):
            return False
        return other.address == self.address

mypy is reporting error: Returning Any from function declared to return "bool" [no-any-return] This seems strange, as it seems like both statements unambiguously return a boolean. Can anyone shed some light on this?

Thanks.

Steve B.
  • 55,454
  • 12
  • 93
  • 132
  • 6
    [`__eq__`](https://docs.python.org/3/reference/datamodel.html?highlight=__eq__#object.__eq__) returns `Any`, not `bool`, as counter-intuitive as this sounds. See also [this question](https://stackoverflow.com/questions/54801832/mypy-eq-incompatible-with-supertype-object). – MrBean Bremen Dec 23 '21 at 07:27
  • To add onto @MrBeanBremen's answer, see https://stackoverflow.com/a/67798096/338710. It seems that this is done for operator overloading reasons. – wickedchicken Jun 14 '23 at 13:37

0 Answers0