[Python-checkins] r68919 - in python/branches/py3k: Doc/library/importlib.rstLib/importlib/NOTES Lib/importlib/_bootstrap.py
Nick Coghlan
ncoghlan at gmail.com
Sun Jan 25 14:34:54 CET 2009
Antoine Pitrou wrote:
> <brett.cannon> writes:
>> + Only class methods are defined by this class to alleviate the need for
>> + instantiation.
>> Why is it so? Is there some obvious performance improvement?
> Instantiation and normal methods are generally a more intuitive coding style
> than having only classmethods.
> Also, it means you can have several instances with different parameters each,
> and it eases testing (you can monkeypatch a test-specific instance without
> disrupting the whole stuff).
Using a class with only class methods is the easiest way to implement a
singleton in Python.
Since the BuiltinImporter and FrozenImporter are singletons by
definition, it makes sense to implement them that way.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
More information about the Python-checkins
mailing list