From c74d324d89ac8631a6c074bd9a2e6dd1482a71ee Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Tue, 28 Jan 2025 13:34:29 +0100 Subject: [PATCH 1/2] chore: relax typing constraints for response action --- gitlab/mixins.py | 4 ++-- gitlab/utils.py | 2 +- gitlab/v4/objects/artifacts.py | 8 ++++---- gitlab/v4/objects/files.py | 2 +- gitlab/v4/objects/jobs.py | 6 +++--- gitlab/v4/objects/packages.py | 4 ++-- gitlab/v4/objects/projects.py | 4 ++-- gitlab/v4/objects/repositories.py | 4 ++-- gitlab/v4/objects/secure_files.py | 4 ++-- gitlab/v4/objects/snippets.py | 4 ++-- tests/functional/api/test_import_export.py | 2 +- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/gitlab/mixins.py b/gitlab/mixins.py index d2e1e0d5e..e738a5c0b 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -640,7 +640,7 @@ def download( def download( self, streamed: Literal[True] = True, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: Literal[False] = False, @@ -652,7 +652,7 @@ def download( def download( self, streamed: bool = False, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: bool = False, diff --git a/gitlab/utils.py b/gitlab/utils.py index b5ca73b09..d26518b3e 100644 --- a/gitlab/utils.py +++ b/gitlab/utils.py @@ -77,7 +77,7 @@ def format(self, record: logging.LogRecord) -> str: def response_content( response: requests.Response, streamed: bool, - action: Optional[Callable[[bytes], None]], + action: Optional[Callable[[bytes], Any]], chunk_size: int, *, iterator: bool, diff --git a/gitlab/v4/objects/artifacts.py b/gitlab/v4/objects/artifacts.py index ce6f90b99..99a231e0f 100644 --- a/gitlab/v4/objects/artifacts.py +++ b/gitlab/v4/objects/artifacts.py @@ -84,7 +84,7 @@ def download( ref_name: str, job: str, streamed: Literal[True] = True, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: Literal[False] = False, @@ -102,7 +102,7 @@ def download( ref_name: str, job: str, streamed: bool = False, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: bool = False, @@ -177,7 +177,7 @@ def raw( artifact_path: str, job: str, streamed: Literal[True] = True, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: Literal[False] = False, @@ -195,7 +195,7 @@ def raw( artifact_path: str, job: str, streamed: bool = False, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: bool = False, diff --git a/gitlab/v4/objects/files.py b/gitlab/v4/objects/files.py index ce2193c2c..e1f7b2290 100644 --- a/gitlab/v4/objects/files.py +++ b/gitlab/v4/objects/files.py @@ -308,7 +308,7 @@ def raw( file_path: str, ref: Optional[str] = None, streamed: Literal[True] = True, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: Literal[False] = False, diff --git a/gitlab/v4/objects/jobs.py b/gitlab/v4/objects/jobs.py index 0c77d76a7..b98255acc 100644 --- a/gitlab/v4/objects/jobs.py +++ b/gitlab/v4/objects/jobs.py @@ -152,7 +152,7 @@ def artifacts( def artifacts( self, streamed: Literal[True] = True, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: Literal[False] = False, @@ -229,7 +229,7 @@ def artifact( self, path: str, streamed: Literal[True] = True, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: Literal[False] = False, @@ -305,7 +305,7 @@ def trace( def trace( self, streamed: Literal[True] = True, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: Literal[False] = False, diff --git a/gitlab/v4/objects/packages.py b/gitlab/v4/objects/packages.py index c31809d80..24c1c6868 100644 --- a/gitlab/v4/objects/packages.py +++ b/gitlab/v4/objects/packages.py @@ -159,7 +159,7 @@ def download( package_version: str, file_name: str, streamed: Literal[True] = True, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: Literal[False] = False, @@ -177,7 +177,7 @@ def download( package_version: str, file_name: str, streamed: bool = False, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: bool = False, diff --git a/gitlab/v4/objects/projects.py b/gitlab/v4/objects/projects.py index e9990afeb..60587fa13 100644 --- a/gitlab/v4/objects/projects.py +++ b/gitlab/v4/objects/projects.py @@ -523,7 +523,7 @@ def snapshot( self, wiki: bool = False, streamed: Literal[True] = True, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: Literal[False] = False, @@ -536,7 +536,7 @@ def snapshot( self, wiki: bool = False, streamed: bool = False, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: bool = False, diff --git a/gitlab/v4/objects/repositories.py b/gitlab/v4/objects/repositories.py index 85dba4b4d..aece75d74 100644 --- a/gitlab/v4/objects/repositories.py +++ b/gitlab/v4/objects/repositories.py @@ -146,7 +146,7 @@ def repository_raw_blob( self, sha: str, streamed: Literal[True] = True, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: Literal[False] = False, @@ -273,7 +273,7 @@ def repository_archive( self, sha: Optional[str] = None, streamed: Literal[True] = True, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: Literal[False] = False, diff --git a/gitlab/v4/objects/secure_files.py b/gitlab/v4/objects/secure_files.py index b329756d3..9a71a6302 100644 --- a/gitlab/v4/objects/secure_files.py +++ b/gitlab/v4/objects/secure_files.py @@ -54,7 +54,7 @@ def download( def download( self, streamed: Literal[True] = True, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: Literal[False] = False, @@ -66,7 +66,7 @@ def download( def download( self, streamed: bool = False, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: bool = False, diff --git a/gitlab/v4/objects/snippets.py b/gitlab/v4/objects/snippets.py index 46c618e33..ebb304a2d 100644 --- a/gitlab/v4/objects/snippets.py +++ b/gitlab/v4/objects/snippets.py @@ -61,7 +61,7 @@ def content( def content( self, streamed: Literal[True] = True, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: Literal[False] = False, @@ -237,7 +237,7 @@ def content( def content( self, streamed: Literal[True] = True, - action: Optional[Callable[[bytes], None]] = None, + action: Optional[Callable[[bytes], Any]] = None, chunk_size: int = 1024, *, iterator: Literal[False] = False, diff --git a/tests/functional/api/test_import_export.py b/tests/functional/api/test_import_export.py index e8d9c9abc..f7444c92c 100644 --- a/tests/functional/api/test_import_export.py +++ b/tests/functional/api/test_import_export.py @@ -50,7 +50,7 @@ def test_project_import_export(gl, project, temp_dir): raise Exception("Project export taking too much time") with open(temp_dir / "gitlab-export.tgz", "wb") as f: - export.download(streamed=True, action=f.write) # type: ignore[call-overload] + export.download(streamed=True, action=f.write) output = gl.projects.import_project( open(temp_dir / "gitlab-export.tgz", "rb"), From ccda1f363f10f5c53e7d4dff49f3e5b854f26620 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Tue, 28 Jan 2025 13:53:16 +0100 Subject: [PATCH 2/2] chore(tests): catch deprecation warnings --- tests/unit/objects/test_projects.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/unit/objects/test_projects.py b/tests/unit/objects/test_projects.py index 84682dea3..65e19459c 100644 --- a/tests/unit/objects/test_projects.py +++ b/tests/unit/objects/test_projects.py @@ -768,11 +768,13 @@ def test_transfer_project(project, resp_transfer_project): def test_project_pull_mirror(project, resp_start_pull_mirroring_project): - project.mirror_pull() + with pytest.warns(DeprecationWarning, match="is deprecated"): + project.mirror_pull() def test_project_pull_mirror_details(project, resp_pull_mirror_details_project): - details = project.mirror_pull_details() + with pytest.warns(DeprecationWarning, match="is deprecated"): + details = project.mirror_pull_details() assert details["last_error"] is None assert details["update_status"] == "finished"