|
|
|
|
|
by JimDabell
247 days ago
|
|
This isn’t. They actually fixed that bug. Then they changed their minds and backed the fix back out again because they don’t think you should write Python that way: > I think EAFP is a very unfortunate and ill-advised practice. They want you to not write the idiomatic Python: try:
foo = bar["baz"]["qux"]
...
except KeyError:
...
…and instead write the non-idiomatic version: if "baz" in bar and "qux" in bar["baz"]:
foo = bar["baz"]["qux"]
...
else:
...
If this were a linter then I would accept that it is going to be opinionated. But this is not a linter, it’s a type checker. Their opinions about EAFP are irrelevant. That’s idiomatic Python. |
|