type_checking_imports.main
1from __future__ import annotations 2 3import typing 4from typing import TYPE_CHECKING 5 6from . import cached_submodule 7 8if typing.TYPE_CHECKING: 9 from typing import Sequence 10 11if TYPE_CHECKING: 12 from typing import Dict 13 14 from .cached_submodule import StrOrInt 15 from .uncached_submodule import StrOrBool 16 17assert cached_submodule 18 19 20def foo(a: Sequence[str], b: Dict[str, str]): 21 """A method with TYPE_CHECKING type annotations.""" 22 23 24var: Sequence[int] = (1, 2, 3) 25"""A variable with TYPE_CHECKING type annotations.""" 26 27 28imported_from_cached_module: StrOrInt = 42 29""" 30A variable with a type annotation that's imported from another file's TYPE_CHECKING block. 31 32https://github.com/mitmproxy/pdoc/issues/648 33""" 34 35imported_from_uncached_module: StrOrBool = True 36""" 37A variable with a type annotation that's imported from another file's TYPE_CHECKING block. 38 39In this case, the module is not in sys.modules outside of TYPE_CHECKING. 40"""
def
foo(a: Sequence[str], b: Dict[str, str]):
21def foo(a: Sequence[str], b: Dict[str, str]): 22 """A method with TYPE_CHECKING type annotations."""
A method with TYPE_CHECKING type annotations.
var: Sequence[int] =
(1, 2, 3)
A variable with TYPE_CHECKING type annotations.
imported_from_cached_module: Union[str, int] =
42
A variable with a type annotation that's imported from another file's TYPE_CHECKING block.
imported_from_uncached_module: Union[str, bool] =
True
A variable with a type annotation that's imported from another file's TYPE_CHECKING block.
In this case, the module is not in sys.modules outside of TYPE_CHECKING.