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

Commitf33b902

Browse files
chore: enable mypy checkwarn_return_any
Update code so that the `warn_return_any` check passes.
1 parent9833632 commitf33b902

File tree

7 files changed

+49
-13
lines changed

7 files changed

+49
-13
lines changed

‎gitlab/base.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
importpprint
2222
importtextwrap
2323
fromtypesimportModuleType
24-
fromtypingimportAny,Dict,Iterable,Optional,Type,Union
24+
fromtypingimportAny,Dict,Iterable,Optional,Type,TYPE_CHECKING,Union
2525

2626
importgitlab
2727
fromgitlabimporttypesasg_types
@@ -245,14 +245,22 @@ def get_id(self) -> Optional[Union[int, str]]:
245245
"""Returns the id of the resource."""
246246
ifself._id_attrisNoneornothasattr(self,self._id_attr):
247247
returnNone
248-
returngetattr(self,self._id_attr)
248+
id_val=getattr(self,self._id_attr)
249+
ifid_valisNone:
250+
returnNone
251+
ifTYPE_CHECKING:
252+
assertisinstance(id_val, (int,str))
253+
returnid_val
249254

250255
@property
251256
def_repr_value(self)->Optional[str]:
252257
"""Safely returns the human-readable resource name if present."""
253258
ifself._repr_attrisNoneornothasattr(self,self._repr_attr):
254259
returnNone
255-
returngetattr(self,self._repr_attr)
260+
repr_val=getattr(self,self._repr_attr)
261+
ifTYPE_CHECKING:
262+
assertisinstance(repr_val,str)
263+
returnrepr_val
256264

257265
@property
258266
defencoded_id(self)->Optional[Union[int,str]]:

‎gitlab/cli.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,18 @@
2323
importre
2424
importsys
2525
fromtypesimportModuleType
26-
fromtypingimportAny,Callable,cast,Dict,Optional,Tuple,Type,TypeVar,Union
26+
fromtypingimport (
27+
Any,
28+
Callable,
29+
cast,
30+
Dict,
31+
Optional,
32+
Tuple,
33+
Type,
34+
TYPE_CHECKING,
35+
TypeVar,
36+
Union,
37+
)
2738

2839
fromrequests.structuresimportCaseInsensitiveDict
2940

@@ -96,8 +107,11 @@ def gitlab_resource_to_cls(
96107
)->Type[RESTObject]:
97108
classes=CaseInsensitiveDict(namespace.__dict__)
98109
lowercase_class=gitlab_resource.replace("-","")
99-
100-
returnclasses[lowercase_class]
110+
class_type=classes[lowercase_class]
111+
ifTYPE_CHECKING:
112+
assertisinstance(class_type,type)
113+
assertissubclass(class_type,RESTObject)
114+
returnclass_type
101115

102116

103117
defcls_to_gitlab_resource(cls:RESTObject)->str:

‎gitlab/client.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ def markdown(
439439
data=self.http_post("/markdown",post_data=post_data,**kwargs)
440440
ifTYPE_CHECKING:
441441
assertnotisinstance(data,requests.Response)
442+
assertisinstance(data["html"],str)
442443
returndata["html"]
443444

444445
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabLicenseError)
@@ -808,7 +809,10 @@ def http_get(
808809
andnotraw
809810
):
810811
try:
811-
returnresult.json()
812+
json_result=result.json()
813+
ifTYPE_CHECKING:
814+
assertisinstance(json_result,dict)
815+
returnjson_result
812816
exceptExceptionase:
813817
raisegitlab.exceptions.GitlabParsingError(
814818
error_message="Failed to parse the server message"
@@ -989,7 +993,10 @@ def http_post(
989993
)
990994
try:
991995
ifresult.headers.get("Content-Type",None)=="application/json":
992-
returnresult.json()
996+
json_result=result.json()
997+
ifTYPE_CHECKING:
998+
assertisinstance(json_result,dict)
999+
returnjson_result
9931000
exceptExceptionase:
9941001
raisegitlab.exceptions.GitlabParsingError(
9951002
error_message="Failed to parse the server message"
@@ -1037,7 +1044,10 @@ def http_put(
10371044
**kwargs,
10381045
)
10391046
try:
1040-
returnresult.json()
1047+
json_result=result.json()
1048+
ifTYPE_CHECKING:
1049+
assertisinstance(json_result,dict)
1050+
returnjson_result
10411051
exceptExceptionase:
10421052
raisegitlab.exceptions.GitlabParsingError(
10431053
error_message="Failed to parse the server message"

‎gitlab/mixins.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,10 @@ def time_stats(self, **kwargs: Any) -> Dict[str, Any]:
746746
# Use the existing time_stats attribute if it exist, otherwise make an
747747
# API call
748748
if"time_stats"inself.attributes:
749-
returnself.attributes["time_stats"]
749+
time_stats=self.attributes["time_stats"]
750+
ifTYPE_CHECKING:
751+
assertisinstance(time_stats,dict)
752+
returntime_stats
750753

751754
path=f"{self.manager.path}/{self.encoded_id}/time_stats"
752755
result=self.manager.gitlab.http_get(path,**kwargs)

‎pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ disallow_untyped_defs = true
1616
no_implicit_reexport =true
1717
strict_equality =true
1818
warn_redundant_casts =true
19+
warn_return_any =true
1920
warn_unused_configs =true
2021
warn_unused_ignores =true
2122

2223
# The following need to have changes made to be able to enable them:
2324
# disallow_any_generics = true
2425
# disallow_untyped_calls = true
2526
# no_implicit_optional = true
26-
# warn_return_any = true
2727

2828
[[tool.mypy.overrides]]# Overrides for currently untyped modules
2929
module = [

‎tests/unit/objects/test_projects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def resp_start_housekeeping():
431431
rsps.add(
432432
method=responses.POST,
433433
url="http://localhost/api/v4/projects/1/housekeeping",
434-
json="0ee4c430667fb7be8461f310",
434+
json={},
435435
content_type="application/json",
436436
status=201,
437437
)

‎tests/unit/test_cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
importpytest
2626

27+
importgitlab.base
2728
fromgitlabimportcli
2829
fromgitlab.exceptionsimportGitlabError
2930

@@ -43,7 +44,7 @@ def test_gitlab_resource_to_cls(gitlab_resource, expected_class):
4344
def_namespace():
4445
pass
4546

46-
ExpectedClass=type(expected_class, (), {})
47+
ExpectedClass=type(expected_class, (gitlab.base.RESTObject,), {})
4748
_namespace.__dict__[expected_class]=ExpectedClass
4849

4950
assertcli.gitlab_resource_to_cls(gitlab_resource,_namespace)==ExpectedClass

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp