summaryrefslogtreecommitdiff
path: root/gitlab/__init__.py
diff options
context:
space:
mode:
authorNejc Habjan <hab.nejc@gmail.com>2021-12-01 01:13:30 +0100
committerGitHub <noreply@github.com>2021-12-01 01:13:30 +0100
commite6582a37a691880a69a75a347389eb4e4e95b20e (patch)
tree51d07a20421b89642f263c08f5cea61ca4924e61 /gitlab/__init__.py
parent09a973ee379d82af05a5080decfaec16d2f4eab3 (diff)
parentb3b0b5f1da5b9da9bf44eac33856ed6eadf37dd6 (diff)
downloadgitlab-e6582a37a691880a69a75a347389eb4e4e95b20e.tar.gz
Merge pull request #1694 from python-gitlab/jlvillal/const_explicit
refactor: explicitly import gitlab.const values into top-level namespace
Diffstat (limited to 'gitlab/__init__.py')
-rw-r--r--gitlab/__init__.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index 7b79f22..824f177 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -17,6 +17,7 @@
"""Wrapper for the GitLab API."""
import warnings
+from typing import Any
import gitlab.config # noqa: F401
from gitlab.__version__ import ( # noqa: F401
@@ -28,7 +29,22 @@ from gitlab.__version__ import ( # noqa: F401
__version__,
)
from gitlab.client import Gitlab, GitlabList # noqa: F401
-from gitlab.const import * # noqa: F401,F403
from gitlab.exceptions import * # noqa: F401,F403
warnings.filterwarnings("default", category=DeprecationWarning, module="^gitlab")
+
+
+# NOTE(jlvillal): We are deprecating access to the gitlab.const values which
+# were previously imported into this namespace by the
+# 'from gitlab.const import *' statement.
+def __getattr__(name: str) -> Any:
+ # Deprecate direct access to constants without namespace
+ if name in gitlab.const._DEPRECATED:
+ warnings.warn(
+ f"\nDirect access to 'gitlab.{name}' is deprecated and will be "
+ f"removed in a future major python-gitlab release. Please "
+ f"use 'gitlab.const.{name}' instead.",
+ DeprecationWarning,
+ )
+ return getattr(gitlab.const, name)
+ raise AttributeError(f"module {__name__} has no attribute {name}")