Defer Django and sqlalchemy imports#1071
Defer Django and sqlalchemy imports#1071adamchainz wants to merge 1 commit intoFactoryBoy:masterfrom
Conversation
a920584 to
ee8d278
Compare
| try: | ||
| from . import mogo | ||
| except ImportError: | ||
| pass | ||
| try: | ||
| from . import mongoengine | ||
| except ImportError: | ||
| pass |
There was a problem hiding this comment.
These two submodules don’t have any library-specific imports, so the try/except was never needed.
There was a problem hiding this comment.
Hi!
Thanks for offering a PR! 🌟
I think these imports are here to allow code such as import factory; factory.mogo.MogoFactory().
Conversely, users who have django as a dependency but do not use it would probably rather avoid loading django at all.
I have suggested such a simplification in the past #760 (see the discussion there) and follow up #766. It was rejected on the basis that it would break imports for users.
Arguably, this code pattern should not have been supported in the first place. I’m still of the opinion this change should land (maybe with a deprecation period to reduce friction for users).
This PR adds another good argument: performance.
|
Oopsie, I now realize I missed line 5 : Your suggested change is much less controversial then. :) |
|
I’m wondering if the same change should be applied to the django module? |
ee8d278 to
6fc6f82
Compare
6fc6f82 to
79bde24
Compare
|
Yeah, good idea. I didn’t do it at first out of laziness. I just made the change and it wasn’t that hard! |
|
I understand the idea behind this change; however, I would prefer to have an agreement on the overall design (in the issue) before jumping into code. At a high level, I would be OK with this kind of change if:
Would it be possible to adjust this idea to match those? I'd rather avoid increasing the burden on maintenance for the library — including issues opened by users who don't understand why they get import errors when calling their factories… |
Fixes #1070.