chore: avoid importing TYPE_CHECKING#1195
Conversation
| from typing import NamedTuple | ||
|
|
||
| from ._elffile import EIClass, EIData, ELFFile, EMachine | ||
|
|
||
| TYPE_CHECKING = False | ||
| if TYPE_CHECKING: |
There was a problem hiding this comment.
This is pointless code churn
|
Provide a real world use case that uses packaging and markedly improves due to saving type importing. I am -1 on this without a real world benefit, while this works in practice isn't not part of the typing standard and adds a lot of churn across the code base. |
|
you're right in the end it always typing always ends up being loaded. Let's wait for PEP781 to properly land in a few years. sorry for the noise. |
|
For context, this is probably inspired by pypa/cibuildwheel#2866, which itself was inspired by henryiii/cibuildwheel#17 (from @hugovk). For cibuildwheel, when combined with lazy imports, it saves about 30% more time, and simplifies the lazy imports a bit (you can't lazy import TYPE_CHECKING and then use it, it reifies immediately). Not sure it's as effective here, though. |
It's only effective for the |
Using
TYPE_CHECKING=Falserather than importing it allows not to import typing altogether which can help with import time.This PR forbids the use of
typing.TYPE_CHECKINGto ensuretypingwill not be imported if unneeded.