Open DimitriPapadopoulos opened 2 weeks ago
Yes, though these are very cheap imports.
I'm also cognizant of #9581...
I was not aware of runtime type checking tools. Perhaps we need to keep the current status quo until we make sure TCH rules do the right thing, taking into account runtime typecheckers.
Not sure they currently do the right thing, at least by default. From TCH001:
Unused imports add a performance overhead at runtime, and risk creating import cycles. If an import is only used in typing-only contexts, it can instead be imported conditionally under an if
TYPE_CHECKING:
block to minimize runtime overhead.If
lint.flake8-type-checking.quote-annotations
is set totrue
, annotations will be wrapped in quotes if doing so would enable the corresponding import to be moved into an ifTYPE_CHECKING:
block.If a class requires that type annotations be available at runtime (as is the case for Pydantic, SQLAlchemy, and other libraries), consider using the
lint.flake8-type-checking.runtime-evaluated-base-classes
andlint.flake8-type-checking.runtime-evaluated-decorators
settings to mark them as such.
OK, I reckon given the uncertainty & low cost of these imports, let's push this off until the ecosystem has had a chance to coalesce on an option...
These imports will only be imported during type checking, not at run time.