Debian Codegraph @

mypy/bogus_type.py

raw
1 """A Bogus[T] type alias for marking when we subvert the type system
2
3 We need this for compiling with mypyc, which inserts runtime
4 typechecks that cause problems when we subvert the type system. So
5 when compiling with mypyc, we turn those places into Any, while
6 keeping the types around for normal typechecks.
7
8 Since this causes the runtime types to be Any, this is best used
9 in places where efficient access to properties is not important.
10 For those cases some other technique should be used.
11 """
12
13 from __future__ import annotations
14
15 from typing import Any, TypeVar
16
17 from mypy_extensions import FlexibleAlias
18
19 T = TypeVar("T")
20
21 # This won't ever be true at runtime, but we consider it true during
22 # mypyc compilations.
23 MYPYC = False
24 if MYPYC:
25 Bogus = FlexibleAlias[T, Any]
26 else:
27 Bogus = FlexibleAlias[T, T]