Open DetachHead opened 2 years ago
I think this should be an option and off by default, it's too disruptive to the expected usage of mypy.
I think this should be an option and off by default, it's too disruptive to the expected usage of mypy.
Why do you say this is too disruptive (given basedmypy is already quite disruptive)? Is it due to the effect it will have on code that is not in a function?
Should variables accessed using nonlocal
also not be narrowed?
It's designed like this intentionally for good reason, and there isn't anything to support the alternative like other languages:
var a: Int? = 0
fun main() {
a ?: return
a + 1 // error: a could be null
a!! + 1 // no error
}
If this was to be default then I would expect there to be some systems available to support it, perhaps mutation tracking.
i usually work around it by defining a new local variable (which is the recommended solution in dart), which seems safer than using a non-null assertion
var a: Int? = 0
fun main() {
val b = a
b ?: return
a + 1 // error: a could be null
b + 1 // no error
}