Python Forum
Static type checking with PyPy
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Static type checking with PyPy
#1
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!
Reply
#2
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.
micseydel likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem usage of static method akbarza 5 555 Feb-03-2024, 07:43 AM
Last Post: paul18fr
  Class member become static Quasar999 1 685 Sep-16-2023, 12:52 PM
Last Post: deanhystad
Photo Output Static image on HDMI2 random816382 0 1,412 Oct-18-2021, 11:21 AM
Last Post: random816382
  Type hinting - return type based on parameter micseydel 2 2,513 Jan-14-2020, 01:20 AM
Last Post: micseydel
  Are there optimizer for static code? AlekseyPython 5 2,594 Nov-03-2019, 07:52 AM
Last Post: AlekseyPython
  Using static methods for library? giu88 4 2,944 Sep-12-2018, 07:52 AM
Last Post: giu88
  Notebook is rendered as static html by github miner_tom 2 3,126 Aug-23-2018, 09:00 PM
Last Post: perfringo
  need to alter static picture to video file mika 1 2,760 Feb-23-2018, 02:11 PM
Last Post: ka06059
  Updating & Accessing a "Static" List Bass 4 4,439 May-23-2017, 07:12 PM
Last Post: Bass

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020