Feature or enhancement
Proposal:
Following on from #109653, further improvements can be made to import times.
Links to previous discussion of this feature:
https://discuss.python.org/t/deferred-computation-evalution-for-toplevels-imports-and-dataclasses/34173
For example:
importlib.metadata is often used for tasks that need to happen at import, e.g. to enumerate/load entry point plug-ins, so it might be worth seeing if we can cut down its own import time a bit more.
importlib.metadata imports zipfile at the top for a function that won't be called in the vast majority of cases. It also imports importlib.abc, which in turn imports importlib.resources, to subclass an ABC with a single, non-abstract method - I assume redefining the method in importlib.metadata would be harmless. Some other less frequently-used imports which are only accessed once or twice, such as json, could also be tucked away in their calling functions.
Linked PRs
Feature or enhancement
Proposal:
Following on from #109653, further improvements can be made to import times.
Links to previous discussion of this feature:
https://discuss.python.org/t/deferred-computation-evalution-for-toplevels-imports-and-dataclasses/34173
For example:
importlib.metadatais often used for tasks that need to happen at import, e.g. to enumerate/load entry point plug-ins, so it might be worth seeing if we can cut down its own import time a bit more.importlib.metadataimportszipfileat the top for a function that won't be called in the vast majority of cases. It also importsimportlib.abc, which in turn importsimportlib.resources, to subclass an ABC with a single, non-abstract method - I assume redefining the method inimportlib.metadatawould be harmless. Some other less frequently-used imports which are only accessed once or twice, such asjson, could also be tucked away in their calling functions.Linked PRs
pprint#122725socketby writingsocket.errorTabas a constant and lazy import modules #121424mimetypes#126979pickle#128732reimport inbase64.b16decodefor a more efficient alternative #128736secrets#128738csv#128858tomllib#128907pstatsandzipfileby removing imports totyping#128981sqlite3#129118subprocess#129427warningsinthreading#129428subprocess(GH-129427) #129447subprocess(GH-129427) #129448warnings#129765traceback#129811reinlocale#129860dataclasses#129925cmdmodule #130056subprocess(GH-129427)" #130201subprocess(GH-129427)" (GH-130201) #130204subprocess(GH-129427)" (GH-130201) #130205sqlite3#131796ast#132024annotationlib#132028enum._simple_enumforannotationlib.Format#132031shlex#132036string#132037email.quoprimimeremovingreimport #132046_types#132103