Skip to content

Commit 24d17b4

Browse files
chore: enable mypy check disallow_any_generics
1 parent 54dd4c3 commit 24d17b4

File tree

8 files changed

+33
-19
lines changed

8 files changed

+33
-19
lines changed

gitlab/client.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def from_config(
277277
@classmethod
278278
def merge_config(
279279
cls,
280-
options: dict,
280+
options: Dict[str, Any],
281281
gitlab_id: Optional[str] = None,
282282
config_files: Optional[List[str]] = None,
283283
) -> "Gitlab":
@@ -330,7 +330,9 @@ def merge_config(
330330
)
331331

332332
@staticmethod
333-
def _merge_auth(options: dict, config: gitlab.config.GitlabConfigParser) -> Tuple:
333+
def _merge_auth(
334+
options: Dict[str, Any], config: gitlab.config.GitlabConfigParser
335+
) -> Tuple[Optional[str], Optional[str], Optional[str]]:
334336
"""
335337
Return a tuple where at most one of 3 token types ever has a value.
336338
Since multiple types of tokens may be present in the environment,
@@ -822,7 +824,7 @@ def http_get(
822824

823825
def http_head(
824826
self, path: str, query_data: Optional[Dict[str, Any]] = None, **kwargs: Any
825-
) -> requests.structures.CaseInsensitiveDict:
827+
) -> "requests.structures.CaseInsensitiveDict[Any]":
826828
"""Make a HEAD request to the Gitlab server.
827829
828830
Args:

gitlab/mixins.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class HeadMixin(_RestManagerBase):
7373
@exc.on_http_error(exc.GitlabHeadError)
7474
def head(
7575
self, id: Optional[Union[str, int]] = None, **kwargs: Any
76-
) -> requests.structures.CaseInsensitiveDict:
76+
) -> "requests.structures.CaseInsensitiveDict[Any]":
7777
"""Retrieve headers from an endpoint.
7878
7979
Args:
@@ -622,7 +622,7 @@ class DownloadMixin(_RestObjectBase):
622622
def download(
623623
self,
624624
streamed: bool = False,
625-
action: Optional[Callable] = None,
625+
action: Optional[Callable[[bytes], None]] = None,
626626
chunk_size: int = 1024,
627627
*,
628628
iterator: bool = False,

gitlab/utils.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __call__(self, chunk: Any) -> None:
3434
def response_content(
3535
response: requests.Response,
3636
streamed: bool,
37-
action: Optional[Callable],
37+
action: Optional[Callable[[bytes], None]],
3838
chunk_size: int,
3939
*,
4040
iterator: bool,
@@ -56,11 +56,11 @@ def response_content(
5656

5757
def _transform_types(
5858
data: Dict[str, Any],
59-
custom_types: dict,
59+
custom_types: Dict[str, Any],
6060
*,
6161
transform_data: bool,
6262
transform_files: Optional[bool] = True,
63-
) -> Tuple[dict, dict]:
63+
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
6464
"""Copy the data dict with attributes that have custom types and transform them
6565
before being sent to the server.
6666
@@ -157,7 +157,7 @@ def remove_none_from_dict(data: Dict[str, Any]) -> Dict[str, Any]:
157157
def warn(
158158
message: str,
159159
*,
160-
category: Optional[Type] = None,
160+
category: Optional[Type[Warning]] = None,
161161
source: Optional[Any] = None,
162162
) -> None:
163163
"""This `warnings.warn` wrapper function attempts to show the location causing the

gitlab/v4/cli.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,16 @@ def do_update(self) -> Dict[str, Any]:
210210
return result
211211

212212

213+
# https://github.com/python/typeshed/issues/7539#issuecomment-1076581049
214+
if TYPE_CHECKING:
215+
_SubparserType = argparse._SubParsersAction[argparse.ArgumentParser]
216+
else:
217+
_SubparserType = Any
218+
219+
213220
def _populate_sub_parser_by_class(
214-
cls: Type[gitlab.base.RESTObject], sub_parser: argparse._SubParsersAction
221+
cls: Type[gitlab.base.RESTObject],
222+
sub_parser: _SubparserType,
215223
) -> None:
216224
mgr_cls_name = f"{cls.__name__}Manager"
217225
mgr_cls = getattr(gitlab.v4.objects, mgr_cls_name)
@@ -301,9 +309,11 @@ def _populate_sub_parser_by_class(
301309
for action_name in cli.custom_actions[name]:
302310
# NOTE(jlvillal): If we put a function for the `default` value of
303311
# the `get` it will always get called, which will break things.
304-
sub_parser_action = action_parsers.get(action_name)
305-
if sub_parser_action is None:
312+
action_parser = action_parsers.get(action_name)
313+
if action_parser is None:
306314
sub_parser_action = sub_parser.add_parser(action_name)
315+
else:
316+
sub_parser_action = action_parser
307317
# Get the attributes for URL/path construction
308318
if mgr_cls._from_parent_attrs:
309319
for x in mgr_cls._from_parent_attrs:
@@ -335,9 +345,11 @@ def _populate_sub_parser_by_class(
335345
for action_name in cli.custom_actions[name]:
336346
# NOTE(jlvillal): If we put a function for the `default` value of
337347
# the `get` it will always get called, which will break things.
338-
sub_parser_action = action_parsers.get(action_name)
339-
if sub_parser_action is None:
348+
action_parser = action_parsers.get(action_name)
349+
if action_parser is None:
340350
sub_parser_action = sub_parser.add_parser(action_name)
351+
else:
352+
sub_parser_action = action_parser
341353
if mgr_cls._from_parent_attrs:
342354
for x in mgr_cls._from_parent_attrs:
343355
sub_parser_action.add_argument(

gitlab/v4/objects/artifacts.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def download(
7575
ref_name: str,
7676
job: str,
7777
streamed: bool = False,
78-
action: Optional[Callable] = None,
78+
action: Optional[Callable[[bytes], None]] = None,
7979
chunk_size: int = 1024,
8080
*,
8181
iterator: bool = False,
@@ -125,7 +125,7 @@ def raw(
125125
artifact_path: str,
126126
job: str,
127127
streamed: bool = False,
128-
action: Optional[Callable] = None,
128+
action: Optional[Callable[[bytes], None]] = None,
129129
chunk_size: int = 1024,
130130
*,
131131
iterator: bool = False,

gitlab/v4/objects/packages.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def download(
103103
package_version: str,
104104
file_name: str,
105105
streamed: bool = False,
106-
action: Optional[Callable] = None,
106+
action: Optional[Callable[[bytes], None]] = None,
107107
chunk_size: int = 1024,
108108
*,
109109
iterator: bool = False,

gitlab/v4/objects/projects.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ def snapshot(
504504
self,
505505
wiki: bool = False,
506506
streamed: bool = False,
507-
action: Optional[Callable] = None,
507+
action: Optional[Callable[[bytes], None]] = None,
508508
chunk_size: int = 1024,
509509
*,
510510
iterator: bool = False,

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ exclude = "build/.*"
99

1010
# 'strict = true' is equivalent to the following:
1111
check_untyped_defs = true
12+
disallow_any_generics = true
1213
disallow_incomplete_defs = true
1314
disallow_subclassing_any = true
1415
disallow_untyped_decorators = true
@@ -21,7 +22,6 @@ warn_unused_configs = true
2122
warn_unused_ignores = true
2223

2324
# The following need to have changes made to be able to enable them:
24-
# disallow_any_generics = true
2525
# disallow_untyped_calls = true
2626
# no_implicit_optional = true
2727

0 commit comments

Comments
 (0)