by leni536 · 4y ago · 0 comments
https://mypy-play.net/?mypy=latest&python=3.10&flags=strict&...
Also clearly a bit of unsoundness is way better than just no type annotations at all, which is the alternative.
void foo() {
var local_a = this.a;
var local_b = this.b;
...
this.a = local_a;
this.b = local_b;
}
But I'd say it's still worth it for the soundness. And I have confidence they'll come up with some improvement. Maybe a way to opt out of setters/getters.https://www.typescriptlang.org/play?#code/MYGwhgzhAEDC0G8BQ1...
That's a very big "just". Typescript and mypy don't look through function call boundaries, doing so would open a lot of problems, I believe.
> or the language could add mutability to the type system.
I agree there, the core issue is that the call to `foo` leaks a an object where the member is rebindable through assignment, but the "flow typing" assumes that doesn't happen. Ideally such a call should be a barrier for flow typing, unless there was a way to specify functions that don't modify their parameter this way (readonly parameters?).
A similar problem but with a global instead:
https://www.typescriptlang.org/play?#code/DYUwLgBAlhBcEDsCuB...
This should be handled differently. Every function should be assumed to modify globals, unless they can be marked to be pure.