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

Commitc5e6ae2

Browse files
authored
Merge pull request#1298 from Yobmod/main
Revert use of Typeguard and therefore typing-extensions==3.10.0.0
2 parents0c1446d +be7bb86 commitc5e6ae2

File tree

15 files changed

+140
-149
lines changed

15 files changed

+140
-149
lines changed

‎.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ignore = E265,E266,E731,E704,
2020
W293, W504,
2121
ANN0 ANN1 ANN2,
2222
TC002,
23-
#TC0, TC1, TC2
23+
TC0, TC1, TC2
2424
# B,
2525
A,
2626
D,

‎git/config.py

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""Module containing module parser implementation able to properly read and write
77
configuration files"""
88

9+
importsys
910
importabc
1011
fromfunctoolsimportwraps
1112
importinspect
@@ -14,12 +15,10 @@
1415
importos
1516
importre
1617
importfnmatch
17-
fromcollectionsimportOrderedDict
1818

1919
fromgit.compatimport (
2020
defenc,
2121
force_text,
22-
with_metaclass,
2322
is_win,
2423
)
2524

@@ -31,15 +30,24 @@
3130

3231
# typing-------------------------------------------------------
3332

34-
fromtypingimport (Any,Callable,IO,List,Dict,Sequence,
35-
TYPE_CHECKING,Tuple,Union,cast,overload)
33+
fromtypingimport (Any,Callable,Generic,IO,List,Dict,Sequence,
34+
TYPE_CHECKING,Tuple,TypeVar,Union,cast,overload)
3635

37-
fromgit.typesimportLit_config_levels,ConfigLevels_Tup,PathLike,TBD,assert_never,is_config_level
36+
fromgit.typesimportLit_config_levels,ConfigLevels_Tup,PathLike,TBD,assert_never,_T
3837

3938
ifTYPE_CHECKING:
4039
fromgit.repo.baseimportRepo
4140
fromioimportBytesIO
4241

42+
T_ConfigParser=TypeVar('T_ConfigParser',bound='GitConfigParser')
43+
44+
ifsys.version_info[:2]< (3,7):
45+
fromcollectionsimportOrderedDict
46+
OrderedDict_OMD=OrderedDict
47+
else:
48+
fromtypingimportOrderedDict
49+
OrderedDict_OMD=OrderedDict[str,List[_T]]
50+
4351
# -------------------------------------------------------------
4452

4553
__all__= ('GitConfigParser','SectionConstraint')
@@ -61,7 +69,6 @@
6169

6270

6371
classMetaParserBuilder(abc.ABCMeta):
64-
6572
"""Utlity class wrapping base-class methods into decorators that assure read-only properties"""
6673
def__new__(cls,name:str,bases:TBD,clsdict:Dict[str,Any])->TBD:
6774
"""
@@ -115,7 +122,7 @@ def flush_changes(self, *args: Any, **kwargs: Any) -> Any:
115122
returnflush_changes
116123

117124

118-
classSectionConstraint(object):
125+
classSectionConstraint(Generic[T_ConfigParser]):
119126

120127
"""Constrains a ConfigParser to only option commands which are constrained to
121128
always use the section we have been initialized with.
@@ -128,7 +135,7 @@ class SectionConstraint(object):
128135
_valid_attrs_= ("get_value","set_value","get","set","getint","getfloat","getboolean","has_option",
129136
"remove_section","remove_option","options")
130137

131-
def__init__(self,config:'GitConfigParser',section:str)->None:
138+
def__init__(self,config:T_ConfigParser,section:str)->None:
132139
self._config=config
133140
self._section_name=section
134141

@@ -149,26 +156,26 @@ def _call_config(self, method: str, *args: Any, **kwargs: Any) -> Any:
149156
returngetattr(self._config,method)(self._section_name,*args,**kwargs)
150157

151158
@property
152-
defconfig(self)->'GitConfigParser':
159+
defconfig(self)->T_ConfigParser:
153160
"""return: Configparser instance we constrain"""
154161
returnself._config
155162

156163
defrelease(self)->None:
157164
"""Equivalent to GitConfigParser.release(), which is called on our underlying parser instance"""
158165
returnself._config.release()
159166

160-
def__enter__(self)->'SectionConstraint':
167+
def__enter__(self)->'SectionConstraint[T_ConfigParser]':
161168
self._config.__enter__()
162169
returnself
163170

164171
def__exit__(self,exception_type:str,exception_value:str,traceback:str)->None:
165172
self._config.__exit__(exception_type,exception_value,traceback)
166173

167174

168-
class_OMD(OrderedDict):
175+
class_OMD(OrderedDict_OMD):
169176
"""Ordered multi-dict."""
170177

171-
def__setitem__(self,key:str,value:Any)->None:
178+
def__setitem__(self,key:str,value:_T)->None:# type: ignore[override]
172179
super(_OMD,self).__setitem__(key, [value])
173180

174181
defadd(self,key:str,value:Any)->None:
@@ -177,7 +184,7 @@ def add(self, key: str, value: Any) -> None:
177184
returnNone
178185
super(_OMD,self).__getitem__(key).append(value)
179186

180-
defsetall(self,key:str,values:Any)->None:
187+
defsetall(self,key:str,values:List[_T])->None:
181188
super(_OMD,self).__setitem__(key,values)
182189

183190
def__getitem__(self,key:str)->Any:
@@ -194,25 +201,17 @@ def setlast(self, key: str, value: Any) -> None:
194201
prior=super(_OMD,self).__getitem__(key)
195202
prior[-1]=value
196203

197-
@overload
198-
defget(self,key:str,default:None= ...)->None:
199-
...
200-
201-
@overload
202-
defget(self,key:str,default:Any= ...)->Any:
203-
...
204-
205-
defget(self,key:str,default:Union[Any,None]=None)->Union[Any,None]:
206-
returnsuper(_OMD,self).get(key, [default])[-1]
204+
defget(self,key:str,default:Union[_T,None]=None)->Union[_T,None]:# type: ignore
205+
returnsuper(_OMD,self).get(key, [default])[-1]# type: ignore
207206

208-
defgetall(self,key:str)->Any:
207+
defgetall(self,key:str)->List[_T]:
209208
returnsuper(_OMD,self).__getitem__(key)
210209

211-
defitems(self)->List[Tuple[str,Any]]:# type: ignore[override]
210+
defitems(self)->List[Tuple[str,_T]]:# type: ignore[override]
212211
"""List of (key, last value for key)."""
213212
return [(k,self[k])forkinself]
214213

215-
defitems_all(self)->List[Tuple[str,List[Any]]]:
214+
defitems_all(self)->List[Tuple[str,List[_T]]]:
216215
"""List of (key, list of values for key)."""
217216
return [(k,self.getall(k))forkinself]
218217

@@ -238,7 +237,7 @@ def get_config_path(config_level: Lit_config_levels) -> str:
238237
assert_never(config_level,ValueError(f"Invalid configuration level:{config_level!r}"))
239238

240239

241-
classGitConfigParser(with_metaclass(MetaParserBuilder,cp.RawConfigParser)):# type: ignore ## mypy does not understand dynamic class creation # noqa: E501
240+
classGitConfigParser(cp.RawConfigParser,metaclass=MetaParserBuilder):
242241

243242
"""Implements specifics required to read git style configuration files.
244243
@@ -298,7 +297,10 @@ def __init__(self, file_or_files: Union[None, PathLike, 'BytesIO', Sequence[Unio
298297
:param repo: Reference to repository to use if [includeIf] sections are found in configuration files.
299298
300299
"""
301-
cp.RawConfigParser.__init__(self,dict_type=_OMD)
300+
cp.RawConfigParser.__init__(self,dict_type=_OMD)# type: ignore[arg-type]
301+
self._dict:Callable[...,_OMD]# type: ignore[assignment] # mypy/typeshed bug
302+
self._defaults:_OMD# type: ignore[assignment] # mypy/typeshed bug
303+
self._sections:_OMD# type: ignore[assignment] # mypy/typeshed bug
302304

303305
# Used in python 3, needs to stay in sync with sections for underlying implementation to work
304306
ifnothasattr(self,'_proxies'):
@@ -309,9 +311,9 @@ def __init__(self, file_or_files: Union[None, PathLike, 'BytesIO', Sequence[Unio
309311
else:
310312
ifconfig_levelisNone:
311313
ifread_only:
312-
self._file_or_files= [get_config_path(f)
314+
self._file_or_files= [get_config_path(cast(Lit_config_levels,f))
313315
forfinCONFIG_LEVELS
314-
ifis_config_level(f)andf!='repository']
316+
iff!='repository']
315317
else:
316318
raiseValueError("No configuration level or configuration files specified")
317319
else:
@@ -424,7 +426,7 @@ def string_decode(v: str) -> str:
424426
# is it a section header?
425427
mo=self.SECTCRE.match(line.strip())
426428
ifnotis_multi_lineandmo:
427-
sectname=mo.group('header').strip()
429+
sectname:str=mo.group('header').strip()
428430
ifsectnameinself._sections:
429431
cursect=self._sections[sectname]
430432
elifsectname==cp.DEFAULTSECT:
@@ -535,7 +537,7 @@ def _included_paths(self) -> List[Tuple[str, str]]:
535537

536538
returnpaths
537539

538-
defread(self)->None:
540+
defread(self)->None:# type: ignore[override]
539541
"""Reads the data stored in the files we have been initialized with. It will
540542
ignore files that cannot be read, possibly leaving an empty configuration
541543
@@ -623,10 +625,11 @@ def write_section(name, section_dict):
623625

624626
ifself._defaults:
625627
write_section(cp.DEFAULTSECT,self._defaults)
628+
value:TBD
626629
forname,valueinself._sections.items():
627630
write_section(name,value)
628631

629-
defitems(self,section_name:str)->List[Tuple[str,str]]:
632+
defitems(self,section_name:str)->List[Tuple[str,str]]:# type: ignore[override]
630633
""":return: list((option, value), ...) pairs of all items in the given section"""
631634
return [(k,v)fork,vinsuper(GitConfigParser,self).items(section_name)ifk!='__name__']
632635

‎git/diff.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
# typing ------------------------------------------------------------------
1717

18-
fromtypingimportAny,Iterator,List,Match,Optional,Tuple,Type,TypeVar,Union,TYPE_CHECKING
19-
fromgit.typesimportPathLike,TBD,Literal,TypeGuard
18+
fromtypingimportAny,Iterator,List,Match,Optional,Tuple,Type,TypeVar,Union,TYPE_CHECKING,cast
19+
fromgit.typesimportPathLike,TBD,Literal
2020

2121
ifTYPE_CHECKING:
2222
from .objects.treeimportTree
@@ -28,9 +28,9 @@
2828
Lit_change_type=Literal['A','D','C','M','R','T','U']
2929

3030

31-
defis_change_type(inp:str)->TypeGuard[Lit_change_type]:
32-
# return True
33-
returninpin ['A','D','C','M','R','T','U']
31+
#def is_change_type(inp: str) -> TypeGuard[Lit_change_type]:
32+
# # return True
33+
# return inp in ['A', 'D', 'C', 'M', 'R', 'T', 'U']
3434

3535
# ------------------------------------------------------------------------
3636

@@ -517,8 +517,8 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non
517517
# Change type can be R100
518518
# R: status letter
519519
# 100: score (in case of copy and rename)
520-
assertis_change_type(_change_type[0]),f"Unexpected value for change_type received:{_change_type[0]}"
521-
change_type:Lit_change_type=_change_type[0]
520+
#assert is_change_type(_change_type[0]), f"Unexpected value for change_type received: {_change_type[0]}"
521+
change_type:Lit_change_type=cast(Lit_change_type,_change_type[0])
522522
score_str=''.join(_change_type[1:])
523523
score=int(score_str)ifscore_str.isdigit()elseNone
524524
path=path.strip()

‎git/index/fun.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@
5353

5454
fromtypingimport (Dict,IO,List,Sequence,TYPE_CHECKING,Tuple,Type,Union,cast)
5555

56-
fromgit.typesimportPathLike,TypeGuard
56+
fromgit.typesimportPathLike
5757

5858
ifTYPE_CHECKING:
5959
from .baseimportIndexFile
60+
fromgit.dbimportGitCmdObjectDB
6061
fromgit.objects.treeimportTreeCacheTup
6162
# from git.objects.fun import EntryTupOrNone
6263

@@ -149,15 +150,15 @@ def write_cache(entries: Sequence[Union[BaseIndexEntry, 'IndexEntry']], stream:
149150
# body
150151
forentryinentries:
151152
beginoffset=tell()
152-
write(entry[4])# ctime
153-
write(entry[5])# mtime
154-
path_str:str=entry[3]
153+
write(entry.ctime_bytes)# ctime
154+
write(entry.mtime_bytes)# mtime
155+
path_str=str(entry.path)
155156
path:bytes=force_bytes(path_str,encoding=defenc)
156157
plen=len(path)&CE_NAMEMASK# path length
157-
assertplen==len(path),"Path %s too long to fit into index"%entry[3]
158-
flags=plen| (entry[2]&CE_NAMEMASK_INV)# clear possible previous values
159-
write(pack(">LLLLLL20sH",entry[6],entry[7],entry[0],
160-
entry[8],entry[9],entry[10],entry[1],flags))
158+
assertplen==len(path),"Path %s too long to fit into index"%entry.path
159+
flags=plen| (entry.flags&CE_NAMEMASK_INV)# clear possible previous values
160+
write(pack(">LLLLLL20sH",entry.dev,entry.inode,entry.mode,
161+
entry.uid,entry.gid,entry.size,entry.binsha,flags))
161162
write(path)
162163
real_size= ((tell()-beginoffset+8)&~7)
163164
write(b"\0"* ((beginoffset+real_size)-tell()))
@@ -188,15 +189,16 @@ def entry_key(*entry: Union[BaseIndexEntry, PathLike, int]) -> Tuple[PathLike, i
188189
""":return: Key suitable to be used for the index.entries dictionary
189190
:param entry: One instance of type BaseIndexEntry or the path and the stage"""
190191

191-
defis_entry_key_tup(entry_key:Tuple)->TypeGuard[Tuple[PathLike,int]]:
192-
returnisinstance(entry_key,tuple)andlen(entry_key)==2
192+
#def is_entry_key_tup(entry_key: Tuple) -> TypeGuard[Tuple[PathLike, int]]:
193+
# return isinstance(entry_key, tuple) and len(entry_key) == 2
193194

194195
iflen(entry)==1:
195196
entry_first=entry[0]
196197
assertisinstance(entry_first,BaseIndexEntry)
197198
return (entry_first.path,entry_first.stage)
198199
else:
199-
assertis_entry_key_tup(entry)
200+
# assert is_entry_key_tup(entry)
201+
entry=cast(Tuple[PathLike,int],entry)
200202
returnentry
201203
# END handle entry
202204

@@ -244,7 +246,7 @@ def read_cache(stream: IO[bytes]) -> Tuple[int, Dict[Tuple[PathLike, int], 'Inde
244246
content_sha=extension_data[-20:]
245247

246248
# truncate the sha in the end as we will dynamically create it anyway
247-
extension_data=extension_data[:-20]
249+
extension_data=extension_data[:-20]
248250

249251
return (version,entries,extension_data,content_sha)
250252

@@ -310,7 +312,7 @@ def _tree_entry_to_baseindexentry(tree_entry: 'TreeCacheTup', stage: int) -> Bas
310312
returnBaseIndexEntry((tree_entry[1],tree_entry[0],stage<<CE_STAGESHIFT,tree_entry[2]))
311313

312314

313-
defaggressive_tree_merge(odb,tree_shas:Sequence[bytes])->List[BaseIndexEntry]:
315+
defaggressive_tree_merge(odb:'GitCmdObjectDB',tree_shas:Sequence[bytes])->List[BaseIndexEntry]:
314316
"""
315317
:return: list of BaseIndexEntries representing the aggressive merge of the given
316318
trees. All valid entries are on stage 0, whereas the conflicting ones are left

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp