Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite4a1f6e

Browse files
nejchJohnVillalovos
authored andcommitted
refactor(const): remove deprecated global constant import
BREAKING CHANGE: Constants defined in `gitlab.const` can no longer be imported globally from `gitlab`.Import them from `gitlab.const` instead.
1 parent4abcd17 commite4a1f6e

File tree

5 files changed

+115
-70
lines changed

5 files changed

+115
-70
lines changed

‎gitlab/__init__.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
"""Wrapper for the GitLab API."""
1818

1919
importwarnings
20-
fromtypingimportAny
2120

2221
importgitlab.config# noqa: F401
23-
fromgitlabimportutilsas_utils
2422
fromgitlab._versionimport (# noqa: F401
2523
__author__,
2624
__copyright__,
@@ -35,24 +33,6 @@
3533
warnings.filterwarnings("default",category=DeprecationWarning,module="^gitlab")
3634

3735

38-
# NOTE(jlvillal): We are deprecating access to the gitlab.const values which
39-
# were previously imported into this namespace by the
40-
# 'from gitlab.const import *' statement.
41-
def__getattr__(name:str)->Any:
42-
# Deprecate direct access to constants without namespace
43-
ifnameingitlab.const._DEPRECATED:
44-
_utils.warn(
45-
message=(
46-
f"\nDirect access to constants as 'gitlab.{name}' is deprecated and "
47-
f"will be removed in a future major python-gitlab release. Please "
48-
f"see the usage of constants in the 'gitlab.const' module instead."
49-
),
50-
category=DeprecationWarning,
51-
)
52-
returngetattr(gitlab.const,name)
53-
raiseAttributeError(f"module{__name__} has no attribute{name}")
54-
55-
5636
__all__= [
5737
"__author__",
5838
"__copyright__",
@@ -63,5 +43,4 @@ def __getattr__(name: str) -> Any:
6343
"Gitlab",
6444
"GitlabList",
6545
]
66-
__all__.extend(gitlab.const._DEPRECATED)
6746
__all__.extend(gitlab.exceptions.__all__)

‎gitlab/const.py

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,6 @@
22

33
fromgitlab._versionimport__title__,__version__
44

5-
# NOTE(jlvillal): '_DEPRECATED' only affects users accessing constants via the
6-
# top-level gitlab.* namespace. See 'gitlab/__init__.py:__getattr__()' for the
7-
# consumer of '_DEPRECATED' For example 'x = gitlab.NO_ACCESS'. We want users
8-
# to instead use constants by doing code like: gitlab.const.NO_ACCESS.
9-
_DEPRECATED= [
10-
"ADMIN_ACCESS",
11-
"DEFAULT_URL",
12-
"DEVELOPER_ACCESS",
13-
"GUEST_ACCESS",
14-
"MAINTAINER_ACCESS",
15-
"MINIMAL_ACCESS",
16-
"NO_ACCESS",
17-
"NOTIFICATION_LEVEL_CUSTOM",
18-
"NOTIFICATION_LEVEL_DISABLED",
19-
"NOTIFICATION_LEVEL_GLOBAL",
20-
"NOTIFICATION_LEVEL_MENTION",
21-
"NOTIFICATION_LEVEL_PARTICIPATING",
22-
"NOTIFICATION_LEVEL_WATCH",
23-
"OWNER_ACCESS",
24-
"REPORTER_ACCESS",
25-
"SEARCH_SCOPE_BLOBS",
26-
"SEARCH_SCOPE_COMMITS",
27-
"SEARCH_SCOPE_GLOBAL_SNIPPET_TITLES",
28-
"SEARCH_SCOPE_ISSUES",
29-
"SEARCH_SCOPE_MERGE_REQUESTS",
30-
"SEARCH_SCOPE_MILESTONES",
31-
"SEARCH_SCOPE_PROJECT_NOTES",
32-
"SEARCH_SCOPE_PROJECTS",
33-
"SEARCH_SCOPE_USERS",
34-
"SEARCH_SCOPE_WIKI_BLOBS",
35-
"USER_AGENT",
36-
"VISIBILITY_INTERNAL",
37-
"VISIBILITY_PRIVATE",
38-
"VISIBILITY_PUBLIC",
39-
]
40-
415

426
classGitlabEnum(str,Enum):
437
"""An enum mixed in with str to make it JSON-serializable."""
@@ -138,5 +102,33 @@ class SearchScope(GitlabEnum):
138102
"Visibility",
139103
"NotificationLevel",
140104
"SearchScope",
105+
"ADMIN_ACCESS",
106+
"DEFAULT_URL",
107+
"DEVELOPER_ACCESS",
108+
"GUEST_ACCESS",
109+
"MAINTAINER_ACCESS",
110+
"MINIMAL_ACCESS",
111+
"NO_ACCESS",
112+
"NOTIFICATION_LEVEL_CUSTOM",
113+
"NOTIFICATION_LEVEL_DISABLED",
114+
"NOTIFICATION_LEVEL_GLOBAL",
115+
"NOTIFICATION_LEVEL_MENTION",
116+
"NOTIFICATION_LEVEL_PARTICIPATING",
117+
"NOTIFICATION_LEVEL_WATCH",
118+
"OWNER_ACCESS",
119+
"REPORTER_ACCESS",
120+
"SEARCH_SCOPE_BLOBS",
121+
"SEARCH_SCOPE_COMMITS",
122+
"SEARCH_SCOPE_GLOBAL_SNIPPET_TITLES",
123+
"SEARCH_SCOPE_ISSUES",
124+
"SEARCH_SCOPE_MERGE_REQUESTS",
125+
"SEARCH_SCOPE_MILESTONES",
126+
"SEARCH_SCOPE_PROJECT_NOTES",
127+
"SEARCH_SCOPE_PROJECTS",
128+
"SEARCH_SCOPE_USERS",
129+
"SEARCH_SCOPE_WIKI_BLOBS",
130+
"USER_AGENT",
131+
"VISIBILITY_INTERNAL",
132+
"VISIBILITY_PRIVATE",
133+
"VISIBILITY_PUBLIC",
141134
]
142-
__all__.extend(_DEPRECATED)

‎gitlab/exceptions.py

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,77 @@ def wrapped_f(*args: Any, **kwargs: Any) -> Any:
342342
returnwrap
343343

344344

345-
__all__= [namefornameindir()ifname.endswith("Error")]
345+
# Export manually to keep mypy happy
346+
__all__= [
347+
"GitlabActivateError",
348+
"GitlabAttachFileError",
349+
"GitlabAuthenticationError",
350+
"GitlabBanError",
351+
"GitlabBlockError",
352+
"GitlabBuildCancelError",
353+
"GitlabBuildEraseError",
354+
"GitlabBuildPlayError",
355+
"GitlabBuildRetryError",
356+
"GitlabCancelError",
357+
"GitlabCherryPickError",
358+
"GitlabCiLintError",
359+
"GitlabConnectionError",
360+
"GitlabCreateError",
361+
"GitlabDeactivateError",
362+
"GitlabDeleteError",
363+
"GitlabDeploymentApprovalError",
364+
"GitlabError",
365+
"GitlabFollowError",
366+
"GitlabGetError",
367+
"GitlabGroupTransferError",
368+
"GitlabHeadError",
369+
"GitlabHousekeepingError",
370+
"GitlabHttpError",
371+
"GitlabImportError",
372+
"GitlabInvitationError",
373+
"GitlabJobCancelError",
374+
"GitlabJobEraseError",
375+
"GitlabJobPlayError",
376+
"GitlabJobRetryError",
377+
"GitlabLicenseError",
378+
"GitlabListError",
379+
"GitlabMRApprovalError",
380+
"GitlabMRClosedError",
381+
"GitlabMRForbiddenError",
382+
"GitlabMROnBuildSuccessError",
383+
"GitlabMRRebaseError",
384+
"GitlabMRResetApprovalError",
385+
"GitlabMarkdownError",
386+
"GitlabOperationError",
387+
"GitlabOwnershipError",
388+
"GitlabParsingError",
389+
"GitlabPipelineCancelError",
390+
"GitlabPipelinePlayError",
391+
"GitlabPipelineRetryError",
392+
"GitlabProjectDeployKeyError",
393+
"GitlabPromoteError",
394+
"GitlabProtectError",
395+
"GitlabRenderError",
396+
"GitlabRepairError",
397+
"GitlabRestoreError",
398+
"GitlabRetryError",
399+
"GitlabRevertError",
400+
"GitlabSearchError",
401+
"GitlabSetError",
402+
"GitlabStopError",
403+
"GitlabSubscribeError",
404+
"GitlabTimeTrackingError",
405+
"GitlabTodoError",
406+
"GitlabTopicMergeError",
407+
"GitlabTransferProjectError",
408+
"GitlabUnbanError",
409+
"GitlabUnblockError",
410+
"GitlabUnfollowError",
411+
"GitlabUnsubscribeError",
412+
"GitlabUpdateError",
413+
"GitlabUploadError",
414+
"GitlabUserApproveError",
415+
"GitlabUserRejectError",
416+
"GitlabVerifyError",
417+
"RedirectError",
418+
]

‎tests/unit/meta/test_v4_objects_imported.pyrenamed to ‎tests/unit/meta/test_imports.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@
66
importpkgutil
77
fromtypingimportSet
88

9+
importgitlab.exceptions
910
importgitlab.v4.objects
1011

1112

12-
deftest_verify_v4_objects_imported()->None:
13+
deftest_all_exceptions_imports_are_exported()->None:
14+
assertgitlab.exceptions.__all__==sorted(
15+
[
16+
name
17+
fornameindir(gitlab.exceptions)
18+
ifname.endswith("Error")andnotname.startswith("_")
19+
]
20+
)
21+
22+
23+
deftest_all_v4_objects_are_imported()->None:
1324
assertlen(gitlab.v4.objects.__path__)==1
1425

1526
init_files:Set[str]=set()

‎tests/unit/test_gitlab.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,16 +336,6 @@ def test_gitlab_user_agent(kwargs, expected_agent):
336336
assertgl.headers["User-Agent"]==expected_agent
337337

338338

339-
deftest_gitlab_deprecated_global_const_warns():
340-
withpytest.deprecated_call(
341-
match="'gitlab.NO_ACCESS' is deprecated.*constants in the 'gitlab.const'"
342-
)asrecord:
343-
no_access=gitlab.NO_ACCESS
344-
345-
assertlen(record)==1
346-
assertno_access==0
347-
348-
349339
deftest_gitlab_enum_const_does_not_warn(recwarn):
350340
no_access=gitlab.const.AccessLevel.NO_ACCESS
351341

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp