Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow string imports outside of packages #736

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

carloshorn
Copy link

Problem description

Currently, string imports are not possible outside of packages.

Minimal reproducible example

The following code snippet executed from a script or Jupyter notebook cell raises an AttributeError: 'NoneType' object has no attribute '__package__'

from dependency_injector import providers
deque_factory = providers.Factory('collections.deque')

The trace back reveals that the exception is thrown in src/dependency_injector/providers.pyx in dependency_injector.providers._resolve_calling_package_name().

Proposal for solution

In case the module in dependency_injector.providers._resolve_calling_package_name is None, the package should also be None. The subsequent call to importlib.import_module will handle the situation properly.

allow string imports outside of packages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant