unpythonic.net Tags

Jeff Epler's blog

About me

I've been a computer programmer since I first started typing in program listings on a Commodore Vic 20 when I was about 8. My hobbies include electronics, CNC manufacturing, photography, beer and winemaking.

I live with my wife and lots of left-over parts from unfinished projects in Lincoln, Nebraska, USA.]

Blog

26 August 2025, 13:18 UTC

Variations on 'if TYPE_CHECKING'


Suggested by mypy documentation:

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from typing import …

Works in mypy, pyright, pyrefly. Found in setuptool_scm generated __version__.py:

TYPE_CHECKING = False
if TYPE_CHECKING:
    from typing import …

Works in mypy, pyright, pyrefly. Best variant for CircuitPython?

def const(x): return x
TYPE_CHECKING = const(0)
if TYPE_CHECKING:
    from typing import …

Works in mypy only. Does not work in pyright, pyrefly:

if False:
    from typing import …

[permalink]

All older entries
Website Copyright © 2004-2024 Jeff Epler