Static type checking with PyPy - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Static type checking with PyPy (/thread-41295.html) |
Static type checking with PyPy - pitosalas - Dec-14-2023 I am using type hints as an experiment to see the pros and cons. I am also using PyPy a an experiment with static type checking. Here's an inconvenient situation. Say variable x can be None | list[int]. And say that I know based on an earlier conditional that x is not None. But if I try to access x[1] I get a type error because the static type checker thinkgs it might be None. What's the pythonic way to handle this? Thanks! RE: Static type checking with PyPy - deanhystad - Dec-14-2023 This happens to me fairly often and every time either mypy found hole in my logic, or I can make mypy happy with a slight modification to the code. Post your code so we can have an informed discussion. |