Skip to content

chore: enable mypy check disallow_any_generics #2211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions gitlab/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def from_config(
@classmethod
def merge_config(
cls,
options: dict,
options: Dict[str, Any],
gitlab_id: Optional[str] = None,
config_files: Optional[List[str]] = None,
) -> "Gitlab":
Expand Down Expand Up @@ -330,7 +330,9 @@ def merge_config(
)

@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,
Expand Down Expand Up @@ -822,7 +824,7 @@ def http_get(

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:
Expand Down
4 changes: 2 additions & 2 deletions gitlab/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions gitlab/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, chunk: Any) -> None:
def response_content(
response: requests.Response,
streamed: bool,
action: Optional[Callable],
action: Optional[Callable[[bytes], None]],
chunk_size: int,
*,
iterator: bool,
Expand All @@ -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.

Expand Down Expand Up @@ -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
Expand Down
22 changes: 17 additions & 5 deletions gitlab/v4/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,16 @@ def do_update(self) -> Dict[str, Any]:
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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions gitlab/v4/objects/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def download(
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,
Expand Down Expand Up @@ -125,7 +125,7 @@ def raw(
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,
Expand Down
2 changes: 1 addition & 1 deletion gitlab/v4/objects/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def download(
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,
Expand Down
2 changes: 1 addition & 1 deletion gitlab/v4/objects/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def snapshot(
self,
wiki: bool = False,
streamed: bool = False,
action: Optional[Callable] = None,
action: Optional[Callable[[bytes], None]] = None,
chunk_size: int = 1024,
*,
iterator: bool = False,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down