2 ms·
I don't know about those other languages, but Rust needs static type information to solve it (which Python doesn't have). Take this code: static NOT_FOUND: i
by duckerude 6y ago
I don't know about those other languages, but Rust needs static type information to solve it (which Python doesn't have). Take this code:
static NOT_FOUND: i32 = 404;
match 403 {
NOT_FOUND => println!("Not found"),
_ => println!("Other"),
}
It doesn't compile:
error[E0530]: match bindings cannot shadow statics
It does compile if you change static to const (and then it does what you want).
But if you misspell NOT_FOUND so it doesn't shadow a static then it misbehaves in the same way as the Python version, with only a few warnings to show for it.
Python has the limitation that there's no fundamental difference between ordinary variables and constants.
I don't know of an alternative proposal for Python that isn't burdensome or also dangerously surprising.