[issue9548] locale can be imported at startup but relies on too many library modules

Marc-Andre Lemburg report at bugs.python.org
Tue Aug 10 00:04:46 CEST 2010


Marc-Andre Lemburg <mal at egenix.com> added the comment:

Antoine Pitrou wrote:
> 
> Antoine Pitrou <pitrou at free.fr> added the comment:
> 
>> I don't think that's the right way forward.
>>
>> It's much easier to either remove the need to import those
>> extra modules or defer their import to actual use within
>> a function.
> 
> The latter has various issues, such as being overly tedious and
> potentially risk (because of the import lock).

Really ? collections is only used in format_string and can easily
be imported there. Note that putting imports into functions is a technique
to remove problems with import locks - it doesn't create any.

> Furthermore, functools.wraps is used as a decorator at the toplevel of
> locale.py, which makes it currently unremovable.

If you look at the code, that decorator is not needed at all. Furthermore
the whole complication was just introduced to make some tests easier
to write.

> The former is easier said than done, and we may end up writing poor
> man's reimplementations of some stdlib functions.

Please be more specific. The modules that have an impact
on import time are collections, functools and re.

>> It would be worthwhile adding a note to the top of the module
>> mentioning the fact that the module is loaded early on by Python
>> and to warn about use of non-builtin module imports.
> 
> Use of non-builtin stdlib modules is legitimate for many functions which
> aren't used in the startup process anyway. The rationale behind the
> patch is precisely to define a subset that is needed at startup and
> shouldn't rely on stdlib facilities. The rest of the locale module is
> allowed to use whatever stdlib facilities it desires, which is always
> much more practical.

I said "warn about the use of non-builtin modules", not disallow
their use. AFAIK, the purpose of the exercise is to reduce the
number of non-builtin modules being loaded early on during
Python startup.

> (note, this is already done elsewhere, for example _abcoll.py or
> _weakrefset.py)

Those are special cases since they are needed for ABCs. locale
is not special enough to warrant such a disruption in module
organization and it's not needed either (see above).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9548>
_______________________________________


More information about the Python-bugs-list mailing list