Open syastrov opened 4 years ago
This would be handy in a few situations, but also require a major extension of our narrowing mechanisms for a use case that I don't think is that common.
My inclination is to say we aren't going to do this, though I'm curious what @JukkaL and @ilevkivskyi think about whether its worth leaving open as a feature request.
I think it is fine to keep this as a low-priority feature request.
In general I think there is a cluster-issue formed (I think I mentioned this before elsewhere) around cleaning-up the binder, partial types, inferring unions from if-else, moving towards SSA in --allow-redefinition
, and generally maybe making binder and related machinery more abstract-interpreter-like. For this I would like to have some pool of potential use-cases we might want to support.
Are you reporting a bug, or opening a feature request? Feature request
Please insert below the code you are checking with mypy,
def my_func() -> bool: return True
created: bool = my_func() a: Optional[int] = None if created: a = 1 z = a + 1 # This is OK
if created: x = a + 1 # Unsupported operand types for + ("None" and "int")
$ mypy a.py a.py:13: error: Unsupported operand types for + ("None" and "int") a.py:13: note: Left operand is of type "Optional[int]" Found 1 error in 1 file (checked 1 source file)