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

Commit1dd4596

Browse files
committed
Add types to refs/reference.py
1 parent4b9ca92 commit1dd4596

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

‎git/refs/reference.py‎

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,29 @@
22
LazyMixin,
33
IterableObj,
44
)
5-
from .symbolicimportSymbolicReference
5+
from .symbolicimportSymbolicReference,T_References
6+
7+
8+
# typing ------------------------------------------------------------------
9+
10+
fromtypingimportAny,Callable,Iterator,List,Match,Optional,Tuple,Type,TypeVar,Union,TYPE_CHECKING# NOQA
11+
fromgit.typesimportCommit_ish,PathLike,TBD,Literal,TypeGuard,_T# NOQA
12+
13+
ifTYPE_CHECKING:
14+
fromgit.repoimportRepo
15+
16+
# ------------------------------------------------------------------------------
617

718

819
__all__= ["Reference"]
920

1021
#{ Utilities
1122

1223

13-
defrequire_remote_ref_path(func):
24+
defrequire_remote_ref_path(func:Callable[...,_T])->Callable[...,_T]:
1425
"""A decorator raising a TypeError if we are not a valid remote, based on the path"""
1526

16-
defwrapper(self,*args):
27+
defwrapper(self:T_References,*args:Any)->_T:
1728
ifnotself.is_remote():
1829
raiseValueError("ref path does not point to a remote reference: %s"%self.path)
1930
returnfunc(self,*args)
@@ -32,7 +43,7 @@ class Reference(SymbolicReference, LazyMixin, IterableObj):
3243
_resolve_ref_on_create=True
3344
_common_path_default="refs"
3445

35-
def__init__(self,repo,path,check_path=True):
46+
def__init__(self,repo:'Repo',path:PathLike,check_path:bool=True)->None:
3647
"""Initialize this instance
3748
:param repo: Our parent repository
3849
@@ -41,16 +52,17 @@ def __init__(self, repo, path, check_path=True):
4152
refs/heads/master
4253
:param check_path: if False, you can provide any path. Otherwise the path must start with the
4354
default path prefix of this type."""
44-
ifcheck_pathandnotpath.startswith(self._common_path_default+'/'):
45-
raiseValueError("Cannot instantiate %r from path %s"% (self.__class__.__name__,path))
55+
ifcheck_pathandnotstr(path).startswith(self._common_path_default+'/'):
56+
raiseValueError(f"Cannot instantiate{self.__class__.__name__!r} from path{path}")
57+
self.path:str# SymbolicReference converts to string atm
4658
super(Reference,self).__init__(repo,path)
4759

48-
def__str__(self):
60+
def__str__(self)->str:
4961
returnself.name
5062

5163
#{ Interface
5264

53-
defset_object(self,object,logmsg=None):# @ReservedAssignment
65+
defset_object(self,object:Commit_ish,logmsg:Union[str,None]=None)->'Reference':# @ReservedAssignment
5466
"""Special version which checks if the head-log needs an update as well
5567
:return: self"""
5668
oldbinsha=None
@@ -84,7 +96,7 @@ def set_object(self, object, logmsg=None): # @ReservedAssignment
8496
# NOTE: Don't have to overwrite properties as the will only work without a the log
8597

8698
@property
87-
defname(self):
99+
defname(self)->str:
88100
""":return: (shortest) Name of this reference - it may contain path components"""
89101
# first two path tokens are can be removed as they are
90102
# refs/heads or refs/tags or refs/remotes
@@ -94,7 +106,8 @@ def name(self):
94106
return'/'.join(tokens[2:])
95107

96108
@classmethod
97-
defiter_items(cls,repo,common_path=None):
109+
defiter_items(cls:Type[T_References],repo:'Repo',common_path:Union[PathLike,None]=None,
110+
*args:Any,**kwargs:Any)->Iterator[T_References]:
98111
"""Equivalent to SymbolicReference.iter_items, but will return non-detached
99112
references as well."""
100113
returncls._iter_items(repo,common_path)
@@ -105,7 +118,7 @@ def iter_items(cls, repo, common_path=None):
105118

106119
@property# type: ignore ## mypy cannot deal with properties with an extra decorator (2021-04-21)
107120
@require_remote_ref_path
108-
defremote_name(self):
121+
defremote_name(self)->str:
109122
"""
110123
:return:
111124
Name of the remote we are a reference of, such as 'origin' for a reference
@@ -116,7 +129,7 @@ def remote_name(self):
116129

117130
@property# type: ignore ## mypy cannot deal with properties with an extra decorator (2021-04-21)
118131
@require_remote_ref_path
119-
defremote_head(self):
132+
defremote_head(self)->str:
120133
""":return: Name of the remote head itself, i.e. master.
121134
:note: The returned name is usually not qualified enough to uniquely identify
122135
a branch"""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp