Twitter user @DanyX23:

TIL: pyright, the python type checking engine that is used by VS Code, has support for exhaustiveness checking for match statements with union types!

If you add the following to your pyproject.toml, you’ll get the attached warning

[tool.pyright] reportMatchNotExhaustive = true

    • FizzyOrange@programming.dev
      link
      fedilink
      arrow-up
      4
      ·
      7 months ago

      Python lets you add static type annotations to your program, so you can say “this variable should be and int or a string”, and that means Pyright (a fantastic static type checker) can tell you if you screw up and forget that it might be a string.