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

Commit8e85791

Browse files
chore: add a UserWarning if bothiterator=True andpage=X are used (#2462)
If a caller calls a `list()` method with both `iterator=True` (or`as_list=False`) and `page=X` then emit a `UserWarning` as the optionsare mutually exclusive.
1 parent585e3a8 commit8e85791

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

‎gitlab/client.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,19 @@ def http_list(
929929

930930
page=kwargs.get("page")
931931

932+
ifiteratorandpageisnotNone:
933+
arg_used_message=f"iterator={iterator}"
934+
ifas_listisnotNone:
935+
arg_used_message=f"as_list={as_list}"
936+
utils.warn(
937+
message=(
938+
f"`{arg_used_message}` and `page={page}` were both specified. "
939+
f"`{arg_used_message}` will be ignored and a `list` will be "
940+
f"returned."
941+
),
942+
category=UserWarning,
943+
)
944+
932945
ifiteratorandpageisNone:
933946
# Generator requested
934947
returnGitlabList(self,url,query_data,**kwargs)

‎tests/unit/test_gitlab_http_methods.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,22 @@ def test_list_request_page_and_iterator(gl):
548548
response_dict["match"]= [responses.matchers.query_param_matcher({"page":"1"})]
549549
responses.add(**response_dict)
550550

551-
result=gl.http_list("/projects",iterator=True,page=1)
551+
withpytest.warns(
552+
UserWarning,match="`iterator=True` and `page=1` were both specified"
553+
):
554+
result=gl.http_list("/projects",iterator=True,page=1)
552555
assertisinstance(result,list)
553556
assertlen(result)==20
554557
assertlen(responses.calls)==1
555558

559+
withpytest.warns(
560+
UserWarning,match="`as_list=False` and `page=1` were both specified"
561+
):
562+
result=gl.http_list("/projects",as_list=False,page=1)
563+
assertisinstance(result,list)
564+
assertlen(result)==20
565+
assertlen(responses.calls)==2
566+
556567

557568
large_list_response= {
558569
"method":responses.GET,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp