summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn L. Villalovos <john@sodarock.com>2022-08-01 00:29:18 -0700
committerJohn L. Villalovos <john@sodarock.com>2022-08-01 00:29:18 -0700
commit24d17b43da16dd11ab37b2cee561d9392c90f32e (patch)
tree2adacb59887c121231dd98cf04523c57674ba9c5
parent54dd4c3f857f82aa8781b0daf22fa2dd3c60c2c4 (diff)
downloadgitlab-24d17b43da16dd11ab37b2cee561d9392c90f32e.tar.gz
chore: enable mypy check `disallow_any_generics`
-rw-r--r--gitlab/client.py8
-rw-r--r--gitlab/mixins.py4
-rw-r--r--gitlab/utils.py8
-rw-r--r--gitlab/v4/cli.py22
-rw-r--r--gitlab/v4/objects/artifacts.py4
-rw-r--r--gitlab/v4/objects/packages.py2
-rw-r--r--gitlab/v4/objects/projects.py2
-rw-r--r--pyproject.toml2
8 files changed, 33 insertions, 19 deletions
diff --git a/gitlab/client.py b/gitlab/client.py
index 97ca636..da4036d 100644
--- a/gitlab/client.py
+++ b/gitlab/client.py
@@ -277,7 +277,7 @@ class Gitlab:
@classmethod
def merge_config(
cls,
- options: dict,
+ options: Dict[str, Any],
gitlab_id: Optional[str] = None,
config_files: Optional[List[str]] = None,
) -> "Gitlab":
@@ -330,7 +330,9 @@ class Gitlab:
)
@staticmethod
- def _merge_auth(options: dict, config: gitlab.config.GitlabConfigParser) -> Tuple:
+ def _merge_auth(
+ options: Dict[str, Any], config: gitlab.config.GitlabConfigParser
+ ) -> Tuple[Optional[str], Optional[str], Optional[str]]:
"""
Return a tuple where at most one of 3 token types ever has a value.
Since multiple types of tokens may be present in the environment,
@@ -822,7 +824,7 @@ class Gitlab:
def http_head(
self, path: str, query_data: Optional[Dict[str, Any]] = None, **kwargs: Any
- ) -> requests.structures.CaseInsensitiveDict:
+ ) -> "requests.structures.CaseInsensitiveDict[Any]":
"""Make a HEAD request to the Gitlab server.
Args:
diff --git a/gitlab/mixins.py b/gitlab/mixins.py
index d58227a..9b5f9aa 100644
--- a/gitlab/mixins.py
+++ b/gitlab/mixins.py
@@ -73,7 +73,7 @@ class HeadMixin(_RestManagerBase):
@exc.on_http_error(exc.GitlabHeadError)
def head(
self, id: Optional[Union[str, int]] = None, **kwargs: Any
- ) -> requests.structures.CaseInsensitiveDict:
+ ) -> "requests.structures.CaseInsensitiveDict[Any]":
"""Retrieve headers from an endpoint.
Args:
@@ -622,7 +622,7 @@ class DownloadMixin(_RestObjectBase):
def download(
self,
streamed: bool = False,
- action: Optional[Callable] = None,
+ action: Optional[Callable[[bytes], None]] = None,
chunk_size: int = 1024,
*,
iterator: bool = False,
diff --git a/gitlab/utils.py b/gitlab/utils.py
index f3d97f7..c8ecd1b 100644
--- a/gitlab/utils.py
+++ b/gitlab/utils.py
@@ -34,7 +34,7 @@ class _StdoutStream:
def response_content(
response: requests.Response,
streamed: bool,
- action: Optional[Callable],
+ action: Optional[Callable[[bytes], None]],
chunk_size: int,
*,
iterator: bool,
@@ -56,11 +56,11 @@ def response_content(
def _transform_types(
data: Dict[str, Any],
- custom_types: dict,
+ custom_types: Dict[str, Any],
*,
transform_data: bool,
transform_files: Optional[bool] = True,
-) -> Tuple[dict, dict]:
+) -> Tuple[Dict[str, Any], Dict[str, Any]]:
"""Copy the data dict with attributes that have custom types and transform them
before being sent to the server.
@@ -157,7 +157,7 @@ def remove_none_from_dict(data: Dict[str, Any]) -> Dict[str, Any]:
def warn(
message: str,
*,
- category: Optional[Type] = None,
+ category: Optional[Type[Warning]] = None,
source: Optional[Any] = None,
) -> None:
"""This `warnings.warn` wrapper function attempts to show the location causing the
diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py
index 48369f6..fbc11c2 100644
--- a/gitlab/v4/cli.py
+++ b/gitlab/v4/cli.py
@@ -210,8 +210,16 @@ class GitlabCLI:
return result
+# https://github.com/python/typeshed/issues/7539#issuecomment-1076581049
+if TYPE_CHECKING:
+ _SubparserType = argparse._SubParsersAction[argparse.ArgumentParser]
+else:
+ _SubparserType = Any
+
+
def _populate_sub_parser_by_class(
- cls: Type[gitlab.base.RESTObject], sub_parser: argparse._SubParsersAction
+ cls: Type[gitlab.base.RESTObject],
+ sub_parser: _SubparserType,
) -> None:
mgr_cls_name = f"{cls.__name__}Manager"
mgr_cls = getattr(gitlab.v4.objects, mgr_cls_name)
@@ -301,9 +309,11 @@ def _populate_sub_parser_by_class(
for action_name in cli.custom_actions[name]:
# NOTE(jlvillal): If we put a function for the `default` value of
# the `get` it will always get called, which will break things.
- sub_parser_action = action_parsers.get(action_name)
- if sub_parser_action is None:
+ action_parser = action_parsers.get(action_name)
+ if action_parser is None:
sub_parser_action = sub_parser.add_parser(action_name)
+ else:
+ sub_parser_action = action_parser
# Get the attributes for URL/path construction
if mgr_cls._from_parent_attrs:
for x in mgr_cls._from_parent_attrs:
@@ -335,9 +345,11 @@ def _populate_sub_parser_by_class(
for action_name in cli.custom_actions[name]:
# NOTE(jlvillal): If we put a function for the `default` value of
# the `get` it will always get called, which will break things.
- sub_parser_action = action_parsers.get(action_name)
- if sub_parser_action is None:
+ action_parser = action_parsers.get(action_name)
+ if action_parser is None:
sub_parser_action = sub_parser.add_parser(action_name)
+ else:
+ sub_parser_action = action_parser
if mgr_cls._from_parent_attrs:
for x in mgr_cls._from_parent_attrs:
sub_parser_action.add_argument(
diff --git a/gitlab/v4/objects/artifacts.py b/gitlab/v4/objects/artifacts.py
index b4a4c0e..f091867 100644
--- a/gitlab/v4/objects/artifacts.py
+++ b/gitlab/v4/objects/artifacts.py
@@ -75,7 +75,7 @@ class ProjectArtifactManager(RESTManager):
ref_name: str,
job: str,
streamed: bool = False,
- action: Optional[Callable] = None,
+ action: Optional[Callable[[bytes], None]] = None,
chunk_size: int = 1024,
*,
iterator: bool = False,
@@ -125,7 +125,7 @@ class ProjectArtifactManager(RESTManager):
artifact_path: str,
job: str,
streamed: bool = False,
- action: Optional[Callable] = None,
+ action: Optional[Callable[[bytes], None]] = None,
chunk_size: int = 1024,
*,
iterator: bool = False,
diff --git a/gitlab/v4/objects/packages.py b/gitlab/v4/objects/packages.py
index 50295e0..9ae2fd5 100644
--- a/gitlab/v4/objects/packages.py
+++ b/gitlab/v4/objects/packages.py
@@ -103,7 +103,7 @@ class GenericPackageManager(RESTManager):
package_version: str,
file_name: str,
streamed: bool = False,
- action: Optional[Callable] = None,
+ action: Optional[Callable[[bytes], None]] = None,
chunk_size: int = 1024,
*,
iterator: bool = False,
diff --git a/gitlab/v4/objects/projects.py b/gitlab/v4/objects/projects.py
index 00c0d7e..36e61f6 100644
--- a/gitlab/v4/objects/projects.py
+++ b/gitlab/v4/objects/projects.py
@@ -504,7 +504,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO
self,
wiki: bool = False,
streamed: bool = False,
- action: Optional[Callable] = None,
+ action: Optional[Callable[[bytes], None]] = None,
chunk_size: int = 1024,
*,
iterator: bool = False,
diff --git a/pyproject.toml b/pyproject.toml
index 544543b..a69c6c4 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -9,6 +9,7 @@ exclude = "build/.*"
# 'strict = true' is equivalent to the following:
check_untyped_defs = true
+disallow_any_generics = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_decorators = true
@@ -21,7 +22,6 @@ warn_unused_configs = true
warn_unused_ignores = true
# The following need to have changes made to be able to enable them:
-# disallow_any_generics = true
# disallow_untyped_calls = true
# no_implicit_optional = true