Open
Description
Importing types can lead to circular imports, longer start up times and unwanted side effects.
I want something like:
from foo.bar import type Baz
def foo(baz: Baz):
print(baz.bat)
Such that foo
, foo.bar
and foo.bar.Baz
are not actually loaded at all.
It could 'import' the symbol as a forward-ref or some type machinery thing. (maybe just the string "Baz")
Alternatives:
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from foo.bar import Baz
def foo(baz: Baz):
print(baz.bat)
This is mega boilerplate, gross, and leads to messy wacky 'type-time' side effects (python/mypy#11503).