From 6b29329b2d2bddfa721c3c47e4ca52eb0855668e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=80=D1=82=D1=8B=D0=BD=D0=BE=D0=B2=20=D0=9C?= =?UTF-8?q?=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=B5=D1=80=D0=B3=D0=B5?= =?UTF-8?q?=D0=B5=D0=B2=D0=B8=D1=87?= Date: Thu, 17 Oct 2024 09:54:24 +0000 Subject: [PATCH] [DOP-20674] Replace ImportError with AttributeError in __getattr__ --- docs/changelog/next_release/+.bugfix.3.rst | 1 + onetl/connection/__init__.py | 2 +- onetl/core/__init__.py | 2 +- onetl/hwm/store/__init__.py | 2 +- onetl/strategy/hwm_store/__init__.py | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 docs/changelog/next_release/+.bugfix.3.rst diff --git a/docs/changelog/next_release/+.bugfix.3.rst b/docs/changelog/next_release/+.bugfix.3.rst new file mode 100644 index 00000000..f8f555e6 --- /dev/null +++ b/docs/changelog/next_release/+.bugfix.3.rst @@ -0,0 +1 @@ +Use ``AttributeError`` instead of ``ImportError`` in module's ``__getattr__`` method, to make code compliant with Python spec. diff --git a/onetl/connection/__init__.py b/onetl/connection/__init__.py index 608beb41..03402fd0 100644 --- a/onetl/connection/__init__.py +++ b/onetl/connection/__init__.py @@ -76,4 +76,4 @@ def __getattr__(name: str): submodule = file_df_connections_modules[name] return getattr(import_module(f"onetl.connection.file_df_connection.{submodule}"), name) - raise ImportError(f"cannot import name {name!r} from {__name__!r}") + raise AttributeError(name) diff --git a/onetl/core/__init__.py b/onetl/core/__init__.py index 9796b173..abbfd0e3 100644 --- a/onetl/core/__init__.py +++ b/onetl/core/__init__.py @@ -40,4 +40,4 @@ def __getattr__(name: str): ) return getattr(import_module(f"onetl.{submodule}"), name) - raise ImportError(f"cannot import name {name!r} from {__name__!r}") + raise AttributeError(name) diff --git a/onetl/hwm/store/__init__.py b/onetl/hwm/store/__init__.py index 4fb2d991..929b1d40 100644 --- a/onetl/hwm/store/__init__.py +++ b/onetl/hwm/store/__init__.py @@ -45,4 +45,4 @@ def __getattr__(name: str): return getattr(import_module("etl_entities.hwm_store"), name) - raise ImportError(f"cannot import name {name!r} from {__name__!r}") + raise AttributeError(name) diff --git a/onetl/strategy/hwm_store/__init__.py b/onetl/strategy/hwm_store/__init__.py index de994c20..2f89a595 100644 --- a/onetl/strategy/hwm_store/__init__.py +++ b/onetl/strategy/hwm_store/__init__.py @@ -39,7 +39,7 @@ def __getattr__(name: str): if name not in __all__: - raise ImportError(f"cannot import name {name!r} from {__name__!r}") + raise AttributeError(name) message = f""" Imports from module {__name__!r} are deprecated since v0.6.0 and will be removed in v1.0.0.