Python Forum

Full Version: Static type checking with PyPy
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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!
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.