← Back to context

Comment by drcongo

16 hours ago

It's also horrible for fasle positives unless your project happens to be the exact same setup as the maintainers' - I had to turn off the actual type checking on it. I've since moved wholesale to the Ty alpha and it feels a hell of a lot smarter.

It also inherits the unfortunate attitude of Pyright that it will warn against idiomatic Python (EAFP) in favour of non-idiomatic Python (LBYL):

https://github.com/microsoft/pyright/issues/1739

https://docs.python.org/3/glossary.html#term-EAFP

https://docs.python.org/3/glossary.html#term-LBYL

  • Sometimes dynamic Python idioms are incompatible with typed Python. I personally think that's fine, since I consider static typing a significant improvement overall.

    • 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.

      2 replies →

  • Eww, what? I hadn’t seen that before. Yikes, I hope the situation’s improved. I’d be butting into that continually.