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

Add support to submodules #1570

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion kombu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
for item in items:
object_origins[item] = _module

sub_modules = ("connection", "entity", "message", "messaging",
"pools", "utils", "common", "serialization")
sub_modules_origins = {}
for sub_module in sub_modules:
sub_modules_origins[sub_module] = "kombu." + sub_module


class module(ModuleType):
"""Customized Python module."""
Expand All @@ -78,6 +84,9 @@ def __getattr__(self, name: str) -> Any:
for extra_name in all_by_module[module.__name__]:
setattr(self, extra_name, getattr(module, extra_name))
return getattr(module, name)
if name in sub_modules_origins:
module = __import__(sub_modules_origins[name], None, None, [])
return module
return ModuleType.__getattribute__(self, name)

def __dir__(self) -> list[str]:
Expand All @@ -97,7 +106,7 @@ def __dir__(self) -> list[str]:
'__file__': __file__,
'__path__': __path__,
'__doc__': __doc__,
'__all__': tuple(object_origins),
'__all__': tuple({**sub_modules_origins, **object_origins}),
'__version__': __version__,
'__author__': __author__,
'__contact__': __contact__,
Expand Down