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

Commit300330d

Browse files
authored
Merge pull request#1307 from Yobmod/main
More types for symbolic.py
2 parentsd858916 +8eedc9d commit300330d

File tree

4 files changed

+41
-41
lines changed

4 files changed

+41
-41
lines changed

‎.github/workflows/pythonpackage.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
-name:Install dependencies and prepare tests
2929
run:|
3030
set -x
31+
3132
python -m pip install --upgrade pip setuptools wheel
3233
python --version; git --version
3334
git submodule update --init --recursive

‎git/refs/remote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# typing ------------------------------------------------------------------
1111

12-
fromtypingimportAny,NoReturn,Union,TYPE_CHECKING
12+
fromtypingimportAny,Iterator,NoReturn,Union,TYPE_CHECKING
1313
fromgit.typesimportPathLike
1414

1515

@@ -28,7 +28,7 @@ class RemoteReference(Head):
2828
@classmethod
2929
defiter_items(cls,repo:'Repo',common_path:Union[PathLike,None]=None,
3030
remote:Union['Remote',None]=None,*args:Any,**kwargs:Any
31-
)->'RemoteReference':
31+
)->Iterator['RemoteReference']:
3232
"""Iterate remote references, and if given, constrain them to the given remote"""
3333
common_path=common_pathorcls._common_path_default
3434
ifremoteisnotNone:

‎git/refs/symbolic.py

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@
1717
BadName
1818
)
1919

20-
importos.pathasosp
21-
2220
from .logimportRefLog
2321

2422
# typing ------------------------------------------------------------------
2523

26-
fromtypingimportAny,Iterator,List,Match,Optional,Tuple,Type,TypeVar,Union,TYPE_CHECKING# NOQA
24+
fromtypingimportAny,Iterator,List,Match,Optional,Tuple,Type,TypeVar,Union,TYPE_CHECKING,cast# NOQA
2725
fromgit.typesimportCommit_ish,PathLike,TBD,Literal# NOQA
2826

2927
ifTYPE_CHECKING:
3028
fromgit.repoimportRepo
29+
fromgit.refsimportHead,TagReference,Reference
3130

3231
T_References=TypeVar('T_References',bound='SymbolicReference')
3332

@@ -37,9 +36,9 @@
3736
__all__= ["SymbolicReference"]
3837

3938

40-
def_git_dir(repo,path):
39+
def_git_dir(repo:'Repo',path:PathLike)->PathLike:
4140
""" Find the git dir that's appropriate for the path"""
42-
name="%s"% (path,)
41+
name=f"{path}"
4342
ifnamein ['HEAD','ORIG_HEAD','FETCH_HEAD','index','logs']:
4443
returnrepo.git_dir
4544
returnrepo.common_dir
@@ -61,44 +60,44 @@ class SymbolicReference(object):
6160

6261
def__init__(self,repo:'Repo',path:PathLike,check_path:bool=False):
6362
self.repo=repo
64-
self.path=str(path)
63+
self.path=path
6564

6665
def__str__(self)->str:
67-
returnself.path
66+
returnstr(self.path)
6867

69-
def__repr__(self):
68+
def__repr__(self)->str:
7069
return'<git.%s "%s">'% (self.__class__.__name__,self.path)
7170

72-
def__eq__(self,other):
71+
def__eq__(self,other:Any)->bool:
7372
ifhasattr(other,'path'):
7473
returnself.path==other.path
7574
returnFalse
7675

77-
def__ne__(self,other):
76+
def__ne__(self,other:Any)->bool:
7877
returnnot (self==other)
7978

80-
def__hash__(self):
79+
def__hash__(self)->int:
8180
returnhash(self.path)
8281

8382
@property
84-
defname(self):
83+
defname(self)->str:
8584
"""
8685
:return:
8786
In case of symbolic references, the shortest assumable name
8887
is the path itself."""
89-
returnself.path
88+
returnstr(self.path)
9089

9190
@property
92-
defabspath(self):
91+
defabspath(self)->PathLike:
9392
returnjoin_path_native(_git_dir(self.repo,self.path),self.path)
9493

9594
@classmethod
96-
def_get_packed_refs_path(cls,repo):
97-
returnosp.join(repo.common_dir,'packed-refs')
95+
def_get_packed_refs_path(cls,repo:'Repo')->str:
96+
returnos.path.join(repo.common_dir,'packed-refs')
9897

9998
@classmethod
100-
def_iter_packed_refs(cls,repo):
101-
"""Returns an iterator yielding pairs of sha1/path pairs (asbytes) for the corresponding refs.
99+
def_iter_packed_refs(cls,repo:'Repo')->Iterator[Tuple[str,str]]:
100+
"""Returns an iterator yielding pairs of sha1/path pairs (asstrings) for the corresponding refs.
102101
:note: The packed refs file will be kept open as long as we iterate"""
103102
try:
104103
withopen(cls._get_packed_refs_path(repo),'rt',encoding='UTF-8')asfp:
@@ -126,7 +125,7 @@ def _iter_packed_refs(cls, repo):
126125
ifline[0]=='^':
127126
continue
128127

129-
yieldtuple(line.split(' ',1))
128+
yieldcast(Tuple[str,str],tuple(line.split(' ',1)))
130129
# END for each line
131130
exceptOSError:
132131
returnNone
@@ -137,7 +136,7 @@ def _iter_packed_refs(cls, repo):
137136
# alright.
138137

139138
@classmethod
140-
defdereference_recursive(cls,repo,ref_path):
139+
defdereference_recursive(cls,repo:'Repo',ref_path:PathLike)->str:
141140
"""
142141
:return: hexsha stored in the reference at the given ref_path, recursively dereferencing all
143142
intermediate references as required
@@ -149,14 +148,14 @@ def dereference_recursive(cls, repo, ref_path):
149148
# END recursive dereferencing
150149

151150
@classmethod
152-
def_get_ref_info_helper(cls,repo,ref_path):
151+
def_get_ref_info_helper(cls,repo:'Repo',ref_path:PathLike):
153152
"""Return: (str(sha), str(target_ref_path)) if available, the sha the file at
154153
rela_path points to, or None. target_ref_path is the reference we
155154
point to, or None"""
156-
tokens=None
155+
tokens:Union[None,List[str],Tuple[str,str]]=None
157156
repodir=_git_dir(repo,ref_path)
158157
try:
159-
withopen(osp.join(repodir,ref_path),'rt',encoding='UTF-8')asfp:
158+
withopen(os.path.join(repodir,ref_path),'rt',encoding='UTF-8')asfp:
160159
value=fp.read().rstrip()
161160
# Don't only split on spaces, but on whitespace, which allows to parse lines like
162161
# 60b64ef992065e2600bfef6187a97f92398a9144 branch 'master' of git-server:/path/to/repo
@@ -447,8 +446,8 @@ def delete(cls, repo, path):
447446
or just "myreference", hence 'refs/' is implied.
448447
Alternatively the symbolic reference to be deleted"""
449448
full_ref_path=cls.to_full_path(path)
450-
abs_path=osp.join(repo.common_dir,full_ref_path)
451-
ifosp.exists(abs_path):
449+
abs_path=os.path.join(repo.common_dir,full_ref_path)
450+
ifos.path.exists(abs_path):
452451
os.remove(abs_path)
453452
else:
454453
# check packed refs
@@ -489,7 +488,7 @@ def delete(cls, repo, path):
489488

490489
# delete the reflog
491490
reflog_path=RefLog.path(cls(repo,full_ref_path))
492-
ifosp.isfile(reflog_path):
491+
ifos.path.isfile(reflog_path):
493492
os.remove(reflog_path)
494493
# END remove reflog
495494

@@ -502,14 +501,14 @@ def _create(cls, repo, path, resolve, reference, force, logmsg=None):
502501
instead"""
503502
git_dir=_git_dir(repo,path)
504503
full_ref_path=cls.to_full_path(path)
505-
abs_ref_path=osp.join(git_dir,full_ref_path)
504+
abs_ref_path=os.path.join(git_dir,full_ref_path)
506505

507506
# figure out target data
508507
target=reference
509508
ifresolve:
510509
target=repo.rev_parse(str(reference))
511510

512-
ifnotforceandosp.isfile(abs_ref_path):
511+
ifnotforceandos.path.isfile(abs_ref_path):
513512
target_data=str(target)
514513
ifisinstance(target,SymbolicReference):
515514
target_data=target.path
@@ -559,7 +558,7 @@ def create(cls, repo: 'Repo', path: PathLike, reference: Union[Commit_ish, str]
559558
:note: This does not alter the current HEAD, index or Working Tree"""
560559
returncls._create(repo,path,cls._resolve_ref_on_create,reference,force,logmsg)
561560

562-
defrename(self,new_path,force=False):
561+
defrename(self,new_path:PathLike,force:bool=False)->'SymbolicReference':
563562
"""Rename self to a new path
564563
565564
:param new_path:
@@ -577,9 +576,9 @@ def rename(self, new_path, force=False):
577576
ifself.path==new_path:
578577
returnself
579578

580-
new_abs_path=osp.join(_git_dir(self.repo,new_path),new_path)
581-
cur_abs_path=osp.join(_git_dir(self.repo,self.path),self.path)
582-
ifosp.isfile(new_abs_path):
579+
new_abs_path=os.path.join(_git_dir(self.repo,new_path),new_path)
580+
cur_abs_path=os.path.join(_git_dir(self.repo,self.path),self.path)
581+
ifos.path.isfile(new_abs_path):
583582
ifnotforce:
584583
# if they point to the same file, its not an error
585584
withopen(new_abs_path,'rb')asfd1:
@@ -594,8 +593,8 @@ def rename(self, new_path, force=False):
594593
os.remove(new_abs_path)
595594
# END handle existing target file
596595

597-
dname=osp.dirname(new_abs_path)
598-
ifnotosp.isdir(dname):
596+
dname=os.path.dirname(new_abs_path)
597+
ifnotos.path.isdir(dname):
599598
os.makedirs(dname)
600599
# END create directory
601600

@@ -630,7 +629,7 @@ def _iter_items(cls: Type[T_References], repo: 'Repo', common_path: Union[PathLi
630629

631630
# read packed refs
632631
for_sha,rela_pathincls._iter_packed_refs(repo):
633-
ifrela_path.startswith(common_path):
632+
ifrela_path.startswith(str(common_path)):
634633
rela_paths.add(rela_path)
635634
# END relative path matches common path
636635
# END packed refs reading
@@ -644,8 +643,8 @@ def _iter_items(cls: Type[T_References], repo: 'Repo', common_path: Union[PathLi
644643
# END for each sorted relative refpath
645644

646645
@classmethod
647-
# type: ignore[override]
648-
defiter_items(cls,repo:'Repo',common_path:Union[PathLike,None]=None,*args,**kwargs):
646+
defiter_items(cls:Type[T_References],repo:'Repo',common_path:Union[PathLike,None]=None,
647+
*args:Any,**kwargs:Any)->Iterator[T_References]:
649648
"""Find all refs in the repository
650649
651650
:param repo: is the Repo
@@ -665,7 +664,7 @@ def iter_items(cls, repo: 'Repo', common_path: Union[PathLike, None] = None, *ar
665664
return (rforrincls._iter_items(repo,common_path)ifr.__class__==SymbolicReferenceornotr.is_detached)
666665

667666
@classmethod
668-
deffrom_path(cls,repo,path):
667+
deffrom_path(cls,repo:'Repo',path:PathLike)->Union['Head','TagReference','Reference']:
669668
"""
670669
:param path: full .git-directory-relative path name to the Reference to instantiate
671670
:note: use to_full_path() if you only have a partial path of a known Reference Type

‎pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ filterwarnings = 'ignore::DeprecationWarning'
1919
# filterwarnings ignore::WarningType # ignores those warnings
2020

2121
[tool.mypy]
22-
# disallow_untyped_defs =True
22+
# disallow_untyped_defs =true
2323
no_implicit_optional =true
2424
warn_redundant_casts =true
2525
# warn_unused_ignores = True

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp