Is there a way to indicate to mypy that a given object/type will always be falsy? For example:
class M(type):
@staticmethod
def __bool__() -> Literal[False]:
return False
class C(metaclass=M):
pass
This, for example, fails in the following case:
x: List[str] = [v for v in ("a", "b", C) if v]
because mypy cannot infer that C is falsy, and thus will not be in the list. If None were used in place of C, mypy does not complain:
x: List[str] = [v for v in ("a", "b", None) if v]
This also fails if C is an instance and __bool__ is instance-bound, i.e.:
class C:
def __bool__(self) -> Literal[False]:
return False
x: List[str] = [v for v in ("a", "b", C()) if v]