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

Commit4e90c11

Browse files
nejchJohnVillalovos
authored andcommitted
refactor: use more python3.9 syntax
1 parent91c4f18 commit4e90c11

File tree

59 files changed

+698
-719
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+698
-719
lines changed

‎docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32
#
43
# python-gitlab documentation build configuration file, created by
54
# sphinx-quickstart on Mon Dec 8 15:17:39 2014.

‎gitlab/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# Copyright (C) 2013-2019 Gauvain Pocentek, 2019-2023 python-gitlab team
43
#

‎gitlab/_backends/protocol.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1+
from __future__importannotations
2+
13
importabc
2-
importsys
3-
fromtypingimportAny,Dict,Optional,Union
4+
fromtypingimportAny,Protocol
45

56
importrequests
67
fromrequests_toolbelt.multipart.encoderimportMultipartEncoder# type: ignore
78

8-
ifsys.version_info>= (3,8):
9-
fromtypingimportProtocol
10-
else:
11-
fromtyping_extensionsimportProtocol
12-
139

1410
classBackendResponse(Protocol):
1511
@abc.abstractmethod
@@ -22,11 +18,11 @@ def http_request(
2218
self,
2319
method:str,
2420
url:str,
25-
json:Optional[Union[Dict[str,Any],bytes]],
26-
data:Optional[Union[Dict[str,Any],MultipartEncoder]],
27-
params:Optional[Any],
28-
timeout:Optional[float],
29-
verify:Optional[Union[bool,str]],
30-
stream:Optional[bool],
21+
json:dict[str,Any]|bytes|None,
22+
data:dict[str,Any]|MultipartEncoder|None,
23+
params:Any|None,
24+
timeout:float|None,
25+
verify:bool|str|None,
26+
stream:bool|None,
3127
**kwargs:Any,
3228
)->BackendResponse: ...

‎gitlab/_backends/requests_backend.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__importannotations
22

33
importdataclasses
4-
fromtypingimportAny,BinaryIO,Dict,Optional,TYPE_CHECKING,Union
4+
fromtypingimportAny,BinaryIO,TYPE_CHECKING
55

66
importrequests
77
fromrequestsimportPreparedRequest
@@ -44,8 +44,8 @@ def __call__(self, r: PreparedRequest) -> PreparedRequest:
4444
@dataclasses.dataclass
4545
classSendData:
4646
content_type:str
47-
data:Optional[Union[Dict[str,Any],MultipartEncoder]]=None
48-
json:Optional[Union[Dict[str,Any],bytes]]=None
47+
data:dict[str,Any]|MultipartEncoder|None=None
48+
json:dict[str,Any]|bytes|None=None
4949

5050
def__post_init__(self)->None:
5151
ifself.jsonisnotNoneandself.dataisnotNone:
@@ -84,7 +84,7 @@ def json(self) -> Any:
8484

8585

8686
classRequestsBackend(protocol.Backend):
87-
def__init__(self,session:Optional[requests.Session]=None)->None:
87+
def__init__(self,session:requests.Session|None=None)->None:
8888
self._client:requests.Session=sessionorrequests.Session()
8989

9090
@property
@@ -93,8 +93,8 @@ def client(self) -> requests.Session:
9393

9494
@staticmethod
9595
defprepare_send_data(
96-
files:Optional[Dict[str,Any]]=None,
97-
post_data:Optional[Union[Dict[str,Any],bytes,BinaryIO]]=None,
96+
files:dict[str,Any]|None=None,
97+
post_data:dict[str,Any]|bytes|BinaryIO|None=None,
9898
raw:bool=False,
9999
)->SendData:
100100
iffiles:
@@ -130,12 +130,12 @@ def http_request(
130130
self,
131131
method:str,
132132
url:str,
133-
json:Optional[Union[Dict[str,Any],bytes]]=None,
134-
data:Optional[Union[Dict[str,Any],MultipartEncoder]]=None,
135-
params:Optional[Any]=None,
136-
timeout:Optional[float]=None,
137-
verify:Optional[Union[bool,str]]=True,
138-
stream:Optional[bool]=False,
133+
json:dict[str,Any]|bytes|None=None,
134+
data:dict[str,Any]|MultipartEncoder|None=None,
135+
params:Any|None=None,
136+
timeout:float|None=None,
137+
verify:bool|str|None=True,
138+
stream:bool|None=False,
139139
**kwargs:Any,
140140
)->RequestsResponse:
141141
"""Make HTTP request

‎gitlab/base.py

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1+
from __future__importannotations
2+
13
importcopy
24
importimportlib
35
importjson
46
importpprint
57
importtextwrap
8+
fromcollections.abcimportIterable
69
fromtypesimportModuleType
710
fromtypingimport (
811
Any,
912
ClassVar,
10-
Dict,
1113
Generic,
12-
Iterable,
13-
Optional,
14-
Type,
1514
TYPE_CHECKING,
1615
TypeVar,
17-
Union,
1816
)
1917

2018
importgitlab
@@ -51,20 +49,20 @@ class RESTObject:
5149
object's ``__repr__()`` method.
5250
"""
5351

54-
_id_attr:Optional[str]="id"
55-
_attrs:Dict[str,Any]
52+
_id_attr:str|None="id"
53+
_attrs:dict[str,Any]
5654
_created_from_list:bool# Indicates if object was created from a list() action
5755
_module:ModuleType
58-
_parent_attrs:Dict[str,Any]
59-
_repr_attr:Optional[str]=None
60-
_updated_attrs:Dict[str,Any]
56+
_parent_attrs:dict[str,Any]
57+
_repr_attr:str|None=None
58+
_updated_attrs:dict[str,Any]
6159
_lazy:bool
62-
manager:"RESTManager[Any]"
60+
manager:RESTManager[Any]
6361

6462
def__init__(
6563
self,
66-
manager:"RESTManager[Any]",
67-
attrs:Dict[str,Any],
64+
manager:RESTManager[Any],
65+
attrs:dict[str,Any],
6866
*,
6967
created_from_list:bool=False,
7068
lazy:bool=False,
@@ -88,13 +86,13 @@ def __init__(
8886
self.__dict__["_parent_attrs"]=self.manager.parent_attrs
8987
self._create_managers()
9088

91-
def__getstate__(self)->Dict[str,Any]:
89+
def__getstate__(self)->dict[str,Any]:
9290
state=self.__dict__.copy()
9391
module=state.pop("_module")
9492
state["_module_name"]=module.__name__
9593
returnstate
9694

97-
def__setstate__(self,state:Dict[str,Any])->None:
95+
def__setstate__(self,state:dict[str,Any])->None:
9896
module_name=state.pop("_module_name")
9997
self.__dict__.update(state)
10098
self.__dict__["_module"]=importlib.import_module(module_name)
@@ -147,7 +145,7 @@ def __getattr__(self, name: str) -> Any:
147145
def__setattr__(self,name:str,value:Any)->None:
148146
self.__dict__["_updated_attrs"][name]=value
149147

150-
defasdict(self,*,with_parent_attrs:bool=False)->Dict[str,Any]:
148+
defasdict(self,*,with_parent_attrs:bool=False)->dict[str,Any]:
151149
data= {}
152150
ifwith_parent_attrs:
153151
data.update(copy.deepcopy(self._parent_attrs))
@@ -156,7 +154,7 @@ def asdict(self, *, with_parent_attrs: bool = False) -> Dict[str, Any]:
156154
returndata
157155

158156
@property
159-
defattributes(self)->Dict[str,Any]:
157+
defattributes(self)->dict[str,Any]:
160158
returnself.asdict(with_parent_attrs=True)
161159

162160
defto_json(self,*,with_parent_attrs:bool=False,**kwargs:Any)->str:
@@ -231,11 +229,11 @@ def _create_managers(self) -> None:
231229
# Since we have our own __setattr__ method, we can't use setattr()
232230
self.__dict__[attr]=manager
233231

234-
def_update_attrs(self,new_attrs:Dict[str,Any])->None:
232+
def_update_attrs(self,new_attrs:dict[str,Any])->None:
235233
self.__dict__["_updated_attrs"]= {}
236234
self.__dict__["_attrs"]=new_attrs
237235

238-
defget_id(self)->Optional[Union[int,str]]:
236+
defget_id(self)->int|str|None:
239237
"""Returns the id of the resource."""
240238
ifself._id_attrisNoneornothasattr(self,self._id_attr):
241239
returnNone
@@ -245,7 +243,7 @@ def get_id(self) -> Optional[Union[int, str]]:
245243
returnid_val
246244

247245
@property
248-
def_repr_value(self)->Optional[str]:
246+
def_repr_value(self)->str|None:
249247
"""Safely returns the human-readable resource name if present."""
250248
ifself._repr_attrisNoneornothasattr(self,self._repr_attr):
251249
returnNone
@@ -255,7 +253,7 @@ def _repr_value(self) -> Optional[str]:
255253
returnrepr_val
256254

257255
@property
258-
defencoded_id(self)->Optional[Union[int,str]]:
256+
defencoded_id(self)->int|str|None:
259257
"""Ensure that the ID is url-encoded so that it can be safely used in a URL
260258
path"""
261259
obj_id=self.get_id()
@@ -280,7 +278,7 @@ class RESTObjectList:
280278
"""
281279

282280
def__init__(
283-
self,manager:"RESTManager[Any]",obj_cls:Type[RESTObject],_list:GitlabList
281+
self,manager:RESTManager[Any],obj_cls:type[RESTObject],_list:GitlabList
284282
)->None:
285283
"""Creates an objects list from a GitlabList.
286284
@@ -296,7 +294,7 @@ def __init__(
296294
self._obj_cls=obj_cls
297295
self._list=_list
298296

299-
def__iter__(self)->"RESTObjectList":
297+
def__iter__(self)->RESTObjectList:
300298
returnself
301299

302300
def__len__(self)->int:
@@ -315,33 +313,33 @@ def current_page(self) -> int:
315313
returnself._list.current_page
316314

317315
@property
318-
defprev_page(self)->Optional[int]:
316+
defprev_page(self)->int|None:
319317
"""The previous page number.
320318
321319
If None, the current page is the first.
322320
"""
323321
returnself._list.prev_page
324322

325323
@property
326-
defnext_page(self)->Optional[int]:
324+
defnext_page(self)->int|None:
327325
"""The next page number.
328326
329327
If None, the current page is the last.
330328
"""
331329
returnself._list.next_page
332330

333331
@property
334-
defper_page(self)->Optional[int]:
332+
defper_page(self)->int|None:
335333
"""The number of items per page."""
336334
returnself._list.per_page
337335

338336
@property
339-
deftotal_pages(self)->Optional[int]:
337+
deftotal_pages(self)->int|None:
340338
"""The total number of pages."""
341339
returnself._list.total_pages
342340

343341
@property
344-
deftotal(self)->Optional[int]:
342+
deftotal(self)->int|None:
345343
"""The total number of items."""
346344
returnself._list.total
347345

@@ -362,15 +360,15 @@ class RESTManager(Generic[TObjCls]):
362360
_update_attrs:g_types.RequiredOptional=g_types.RequiredOptional()
363361
_path:ClassVar[str]
364362
_obj_cls:type[TObjCls]
365-
_from_parent_attrs:Dict[str,Any]= {}
366-
_types:Dict[str,Type[g_types.GitlabAttribute]]= {}
363+
_from_parent_attrs:dict[str,Any]= {}
364+
_types:dict[str,type[g_types.GitlabAttribute]]= {}
367365

368366
_computed_path:str
369-
_parent:Optional[RESTObject]
370-
_parent_attrs:Dict[str,Any]
367+
_parent:RESTObject|None
368+
_parent_attrs:dict[str,Any]
371369
gitlab:Gitlab
372370

373-
def__init__(self,gl:Gitlab,parent:Optional[RESTObject]=None)->None:
371+
def__init__(self,gl:Gitlab,parent:RESTObject|None=None)->None:
374372
"""REST manager constructor.
375373
376374
Args:
@@ -382,17 +380,17 @@ def __init__(self, gl: Gitlab, parent: Optional[RESTObject] = None) -> None:
382380
self._computed_path=self._compute_path()
383381

384382
@property
385-
defparent_attrs(self)->Optional[Dict[str,Any]]:
383+
defparent_attrs(self)->dict[str,Any]|None:
386384
returnself._parent_attrs
387385

388-
def_compute_path(self,path:Optional[str]=None)->str:
386+
def_compute_path(self,path:str|None=None)->str:
389387
self._parent_attrs= {}
390388
ifpathisNone:
391389
path=self._path
392390
ifself._parentisNoneornotself._from_parent_attrs:
393391
returnpath
394392

395-
data:Dict[str,Optional[gitlab.utils.EncodedId]]= {}
393+
data:dict[str,gitlab.utils.EncodedId|None]= {}
396394
forself_attr,parent_attrinself._from_parent_attrs.items():
397395
ifnothasattr(self._parent,parent_attr):
398396
data[self_attr]=None

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp