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

Commitabc2b9d

Browse files
committed
refactor: use more python3.9 syntax
1 parentb3834dc commitabc2b9d

Some content is hidden

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

53 files changed

+773
-821
lines changed

‎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: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
from __future__importannotations
2+
13
importcopy
24
importimportlib
35
importjson
46
importpprint
57
importtextwrap
8+
fromcollections.abcimportIterable
69
fromtypesimportModuleType
7-
fromtypingimportAny,Dict,Iterable,Optional,Type,TYPE_CHECKING,Union
10+
fromtypingimportAny,TYPE_CHECKING
811

912
importgitlab
1013
fromgitlabimporttypesasg_types
@@ -40,20 +43,20 @@ class RESTObject:
4043
object's ``__repr__()`` method.
4144
"""
4245

43-
_id_attr:Optional[str]="id"
44-
_attrs:Dict[str,Any]
46+
_id_attr:str|None="id"
47+
_attrs:dict[str,Any]
4548
_created_from_list:bool# Indicates if object was created from a list() action
4649
_module:ModuleType
47-
_parent_attrs:Dict[str,Any]
48-
_repr_attr:Optional[str]=None
49-
_updated_attrs:Dict[str,Any]
50+
_parent_attrs:dict[str,Any]
51+
_repr_attr:str|None=None
52+
_updated_attrs:dict[str,Any]
5053
_lazy:bool
51-
manager:"RESTManager"
54+
manager:RESTManager
5255

5356
def__init__(
5457
self,
55-
manager:"RESTManager",
56-
attrs:Dict[str,Any],
58+
manager:RESTManager,
59+
attrs:dict[str,Any],
5760
*,
5861
created_from_list:bool=False,
5962
lazy:bool=False,
@@ -77,13 +80,13 @@ def __init__(
7780
self.__dict__["_parent_attrs"]=self.manager.parent_attrs
7881
self._create_managers()
7982

80-
def__getstate__(self)->Dict[str,Any]:
83+
def__getstate__(self)->dict[str,Any]:
8184
state=self.__dict__.copy()
8285
module=state.pop("_module")
8386
state["_module_name"]=module.__name__
8487
returnstate
8588

86-
def__setstate__(self,state:Dict[str,Any])->None:
89+
def__setstate__(self,state:dict[str,Any])->None:
8790
module_name=state.pop("_module_name")
8891
self.__dict__.update(state)
8992
self.__dict__["_module"]=importlib.import_module(module_name)
@@ -136,7 +139,7 @@ def __getattr__(self, name: str) -> Any:
136139
def__setattr__(self,name:str,value:Any)->None:
137140
self.__dict__["_updated_attrs"][name]=value
138141

139-
defasdict(self,*,with_parent_attrs:bool=False)->Dict[str,Any]:
142+
defasdict(self,*,with_parent_attrs:bool=False)->dict[str,Any]:
140143
data= {}
141144
ifwith_parent_attrs:
142145
data.update(copy.deepcopy(self._parent_attrs))
@@ -145,7 +148,7 @@ def asdict(self, *, with_parent_attrs: bool = False) -> Dict[str, Any]:
145148
returndata
146149

147150
@property
148-
defattributes(self)->Dict[str,Any]:
151+
defattributes(self)->dict[str,Any]:
149152
returnself.asdict(with_parent_attrs=True)
150153

151154
defto_json(self,*,with_parent_attrs:bool=False,**kwargs:Any)->str:
@@ -220,11 +223,11 @@ def _create_managers(self) -> None:
220223
# Since we have our own __setattr__ method, we can't use setattr()
221224
self.__dict__[attr]=manager
222225

223-
def_update_attrs(self,new_attrs:Dict[str,Any])->None:
226+
def_update_attrs(self,new_attrs:dict[str,Any])->None:
224227
self.__dict__["_updated_attrs"]= {}
225228
self.__dict__["_attrs"]=new_attrs
226229

227-
defget_id(self)->Optional[Union[int,str]]:
230+
defget_id(self)->int|str|None:
228231
"""Returns the id of the resource."""
229232
ifself._id_attrisNoneornothasattr(self,self._id_attr):
230233
returnNone
@@ -234,7 +237,7 @@ def get_id(self) -> Optional[Union[int, str]]:
234237
returnid_val
235238

236239
@property
237-
def_repr_value(self)->Optional[str]:
240+
def_repr_value(self)->str|None:
238241
"""Safely returns the human-readable resource name if present."""
239242
ifself._repr_attrisNoneornothasattr(self,self._repr_attr):
240243
returnNone
@@ -244,7 +247,7 @@ def _repr_value(self) -> Optional[str]:
244247
returnrepr_val
245248

246249
@property
247-
defencoded_id(self)->Optional[Union[int,str]]:
250+
defencoded_id(self)->int|str|None:
248251
"""Ensure that the ID is url-encoded so that it can be safely used in a URL
249252
path"""
250253
obj_id=self.get_id()
@@ -269,7 +272,7 @@ class RESTObjectList:
269272
"""
270273

271274
def__init__(
272-
self,manager:"RESTManager",obj_cls:Type[RESTObject],_list:GitlabList
275+
self,manager:RESTManager,obj_cls:type[RESTObject],_list:GitlabList
273276
)->None:
274277
"""Creates an objects list from a GitlabList.
275278
@@ -285,7 +288,7 @@ def __init__(
285288
self._obj_cls=obj_cls
286289
self._list=_list
287290

288-
def__iter__(self)->"RESTObjectList":
291+
def__iter__(self)->RESTObjectList:
289292
returnself
290293

291294
def__len__(self)->int:
@@ -304,33 +307,33 @@ def current_page(self) -> int:
304307
returnself._list.current_page
305308

306309
@property
307-
defprev_page(self)->Optional[int]:
310+
defprev_page(self)->int|None:
308311
"""The previous page number.
309312
310313
If None, the current page is the first.
311314
"""
312315
returnself._list.prev_page
313316

314317
@property
315-
defnext_page(self)->Optional[int]:
318+
defnext_page(self)->int|None:
316319
"""The next page number.
317320
318321
If None, the current page is the last.
319322
"""
320323
returnself._list.next_page
321324

322325
@property
323-
defper_page(self)->Optional[int]:
326+
defper_page(self)->int|None:
324327
"""The number of items per page."""
325328
returnself._list.per_page
326329

327330
@property
328-
deftotal_pages(self)->Optional[int]:
331+
deftotal_pages(self)->int|None:
329332
"""The total number of pages."""
330333
returnself._list.total_pages
331334

332335
@property
333-
deftotal(self)->Optional[int]:
336+
deftotal(self)->int|None:
334337
"""The total number of items."""
335338
returnself._list.total
336339

@@ -346,17 +349,17 @@ class RESTManager:
346349

347350
_create_attrs:g_types.RequiredOptional=g_types.RequiredOptional()
348351
_update_attrs:g_types.RequiredOptional=g_types.RequiredOptional()
349-
_path:Optional[str]=None
350-
_obj_cls:Optional[Type[RESTObject]]=None
351-
_from_parent_attrs:Dict[str,Any]= {}
352-
_types:Dict[str,Type[g_types.GitlabAttribute]]= {}
353-
354-
_computed_path:Optional[str]
355-
_parent:Optional[RESTObject]
356-
_parent_attrs:Dict[str,Any]
352+
_path:str|None=None
353+
_obj_cls:type[RESTObject]|None=None
354+
_from_parent_attrs:dict[str,Any]= {}
355+
_types:dict[str,type[g_types.GitlabAttribute]]= {}
356+
357+
_computed_path:str|None
358+
_parent:RESTObject|None
359+
_parent_attrs:dict[str,Any]
357360
gitlab:Gitlab
358361

359-
def__init__(self,gl:Gitlab,parent:Optional[RESTObject]=None)->None:
362+
def__init__(self,gl:Gitlab,parent:RESTObject|None=None)->None:
360363
"""REST manager constructor.
361364
362365
Args:
@@ -368,10 +371,10 @@ def __init__(self, gl: Gitlab, parent: Optional[RESTObject] = None) -> None:
368371
self._computed_path=self._compute_path()
369372

370373
@property
371-
defparent_attrs(self)->Optional[Dict[str,Any]]:
374+
defparent_attrs(self)->dict[str,Any]|None:
372375
returnself._parent_attrs
373376

374-
def_compute_path(self,path:Optional[str]=None)->Optional[str]:
377+
def_compute_path(self,path:str|None=None)->str|None:
375378
self._parent_attrs= {}
376379
ifpathisNone:
377380
path=self._path
@@ -380,7 +383,7 @@ def _compute_path(self, path: Optional[str] = None) -> Optional[str]:
380383
ifself._parentisNoneornotself._from_parent_attrs:
381384
returnpath
382385

383-
data:Dict[str,Optional[gitlab.utils.EncodedId]]= {}
386+
data:dict[str,gitlab.utils.EncodedId|None]= {}
384387
forself_attr,parent_attrinself._from_parent_attrs.items():
385388
ifnothasattr(self._parent,parent_attr):
386389
data[self_attr]=None
@@ -390,5 +393,5 @@ def _compute_path(self, path: Optional[str] = None) -> Optional[str]:
390393
returnpath.format(**data)
391394

392395
@property
393-
defpath(self)->Optional[str]:
396+
defpath(self)->str|None:
394397
returnself._computed_path

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp