The problem
factory_boy/__init__.py uses this pattern for its optional sub-packages:
try:
from . import alchemy
except ImportError:
pass
I have a Django project that uses factory_boy a lot, and imports it even in view code. It also happens that the project has sqlalchemy installed for another tool, but it doesn’t use it directly.
On a importtime-waterfall profile, I noticed that importing factory_boy.alchemy takes ~300ms, nearly all in sqlalchemy and its submodules.
It would be great if importing factory_boy didn’t automatically import sqlalchemy.
Proposed solution
Defer the few sqlalchemy imports in factory.alchemy to the functions that use them. Drop the except ImportError pattern in factory_boy since it should then work regardless of whether sqlalchemy is installed.
Extra notes
None.
The problem
factory_boy/__init__.pyuses this pattern for its optional sub-packages:I have a Django project that uses
factory_boya lot, and imports it even in view code. It also happens that the project hassqlalchemyinstalled for another tool, but it doesn’t use it directly.On a importtime-waterfall profile, I noticed that importing
factory_boy.alchemytakes ~300ms, nearly all insqlalchemyand its submodules.It would be great if importing
factory_boydidn’t automatically importsqlalchemy.Proposed solution
Defer the few
sqlalchemyimports infactory.alchemyto the functions that use them. Drop theexcept ImportErrorpattern infactory_boysince it should then work regardless of whethersqlalchemyis installed.Extra notes
None.