Skip to content

Commit

Permalink
Use __getattr__ for re-export
Browse files Browse the repository at this point in the history
Co-authored-by: Oleh Prypin <oleh@pryp.in>
  • Loading branch information
akx and oprypin committed Nov 22, 2023
1 parent 3ac94cf commit 25467f9
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions babel/messages/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,19 +1109,16 @@ def parse_keywords(strings: Iterable[str] = ()):
return keywords


try:
def __getattr__(name: str):
# Re-exports for backwards compatibility;
# `setuptools_frontend` is the canonical import location.
from babel.messages.setuptools_frontend import (
check_message_extractors, # noqa: F401
compile_catalog, # noqa: F401
extract_messages, # noqa: F401
init_catalog, # noqa: F401
update_catalog, # noqa: F401
)
except ImportError:
# We expect this to mean that neither setuptools or distutils are installed.
pass
if name in {'check_message_extractors', 'compile_catalog', 'extract_messages', 'init_catalog', 'update_catalog'}:
from babel.messages import setuptools_frontend

Check warning on line 1116 in babel/messages/frontend.py

View check run for this annotation

Codecov / codecov/patch

babel/messages/frontend.py#L1116

Added line #L1116 was not covered by tests

return getattr(setuptools_frontend, name)

Check warning on line 1118 in babel/messages/frontend.py

View check run for this annotation

Codecov / codecov/patch

babel/messages/frontend.py#L1118

Added line #L1118 was not covered by tests

raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


if __name__ == '__main__':
main()

0 comments on commit 25467f9

Please sign in to comment.