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

Commitac39679

Browse files
committed
Make types in refs compatible with previous
1 parent8fc25c6 commitac39679

File tree

6 files changed

+59
-45
lines changed

6 files changed

+59
-45
lines changed

‎git/cmd.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
PIPE
1616
)
1717
importsubprocess
18-
importsys
1918
importthreading
2019
fromtextwrapimportdedent
2120

@@ -539,7 +538,7 @@ def __iter__(self) -> 'Git.CatFileContentStream':
539538
returnself
540539

541540
def__next__(self)->bytes:
542-
returnself.next()
541+
returnnext(self)
543542

544543
defnext(self)->bytes:
545544
line=self.readline()
@@ -799,10 +798,7 @@ def execute(self,
799798
ifkill_after_timeout:
800799
raiseGitCommandError(redacted_command,'"kill_after_timeout" feature is not supported on Windows.')
801800
else:
802-
ifsys.version_info[0]>2:
803-
cmd_not_found_exception=FileNotFoundError# NOQA # exists, flake8 unknown @UndefinedVariable
804-
else:
805-
cmd_not_found_exception=OSError
801+
cmd_not_found_exception=FileNotFoundError# NOQA # exists, flake8 unknown @UndefinedVariable
806802
# end handle
807803

808804
stdout_sink= (PIPE
@@ -1070,8 +1066,8 @@ def _call_process(self, method: str, *args: Any, **kwargs: Any
10701066
It contains key-values for the following:
10711067
- the :meth:`execute()` kwds, as listed in :var:`execute_kwargs`;
10721068
- "command options" to be converted by :meth:`transform_kwargs()`;
1073-
- the `'insert_kwargs_after'` key which its value must match one of ``*args``,
1074-
and any cmd-options will be appended after the matched arg.
1069+
- the `'insert_kwargs_after'` key which its value must match one of ``*args``
1070+
and any cmd-options will be appended after the matched arg.
10751071
10761072
Examples::
10771073

‎git/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def get_config_path(config_level: Lit_config_levels) -> str:
238238
assert_never(config_level,ValueError(f"Invalid configuration level:{config_level!r}"))
239239

240240

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

243243
"""Implements specifics required to read git style configuration files.
244244

‎git/db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
ifTYPE_CHECKING:
1919
fromgit.cmdimportGit
20-
20+
2121

2222
# --------------------------------------------------------
2323

‎git/diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def diff(self, other: Union[Type['Index'], 'Tree', 'Commit', None, str, object]
143143
paths= [paths]
144144

145145
ifhasattr(self,'Has_Repo'):
146-
self.repo:Repo=self.repo
146+
self.repo:'Repo'=self.repo
147147

148148
diff_cmd=self.repo.git.diff
149149
ifotherisself.Index:

‎git/remote.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636

3737
# typing-------------------------------------------------------
3838

39-
fromtypingimportAny,Callable,Dict,Iterator,List,Optional,Sequence,TYPE_CHECKING,Union,overload
39+
fromtypingimport (Any,Callable,Dict,Iterator,List,NoReturn,Optional,Sequence,# NOQA[TC002]
40+
TYPE_CHECKING,Type,Union,overload)
4041

41-
fromgit.typesimportPathLike,Literal,TBD,TypeGuard,Commit_ish
42+
fromgit.typesimportPathLike,Literal,TBD,TypeGuard,Commit_ish# NOQA[TC002]
4243

4344
ifTYPE_CHECKING:
4445
fromgit.repo.baseimportRepo
@@ -83,17 +84,17 @@ def add_progress(kwargs: Any, git: Git,
8384
#} END utilities
8485

8586

86-
@overload
87+
@overload
8788
defto_progress_instance(progress:None)->RemoteProgress:
8889
...
8990

9091

91-
@overload
92+
@overload
9293
defto_progress_instance(progress:Callable[...,Any])->CallableRemoteProgress:
9394
...
9495

9596

96-
@overload
97+
@overload
9798
defto_progress_instance(progress:RemoteProgress)->RemoteProgress:
9899
...
99100

@@ -155,11 +156,11 @@ def __init__(self, flags: int, local_ref: Union[SymbolicReference, None], remote
155156
self._old_commit_sha=old_commit
156157
self.summary=summary
157158

158-
@property
159-
defold_commit(self)->Union[str,SymbolicReference,'Commit_ish',None]:
159+
@property
160+
defold_commit(self)->Union[str,SymbolicReference,Commit_ish,None]:
160161
returnself._old_commit_shaandself._remote.repo.commit(self._old_commit_sha)orNone
161162

162-
@property
163+
@property
163164
defremote_ref(self)->Union[RemoteReference,TagReference]:
164165
"""
165166
:return:
@@ -175,7 +176,7 @@ def remote_ref(self) -> Union[RemoteReference, TagReference]:
175176
raiseValueError("Could not handle remote ref: %r"%self.remote_ref_string)
176177
# END
177178

178-
@classmethod
179+
@classmethod
179180
def_from_line(cls,remote:'Remote',line:str)->'PushInfo':
180181
"""Create a new PushInfo instance as parsed from line which is expected to be like
181182
refs/heads/master:refs/heads/master 05d2687..1d0568e as bytes"""
@@ -228,6 +229,11 @@ def _from_line(cls, remote: 'Remote', line: str) -> 'PushInfo':
228229

229230
returnPushInfo(flags,from_ref,to_ref_string,remote,old_commit,summary)
230231

232+
@classmethod
233+
defiter_items(cls,repo:'Repo',*args:Any,**kwargs:Any
234+
)->NoReturn:# -> Iterator['PushInfo']:
235+
raiseNotImplementedError
236+
231237

232238
classFetchInfo(IterableObj,object):
233239

@@ -262,7 +268,7 @@ class FetchInfo(IterableObj, object):
262268
'-':TAG_UPDATE,
263269
}# type: Dict[flagKeyLiteral, int]
264270

265-
@classmethod
271+
@classmethod
266272
defrefresh(cls)->Literal[True]:
267273
"""This gets called by the refresh function (see the top level
268274
__init__).
@@ -301,25 +307,25 @@ def __init__(self, ref: SymbolicReference, flags: int, note: str = '',
301307
def__str__(self)->str:
302308
returnself.name
303309

304-
@property
310+
@property
305311
defname(self)->str:
306312
""":return: Name of our remote ref"""
307313
returnself.ref.name
308314

309-
@property
315+
@property
310316
defcommit(self)->Commit_ish:
311317
""":return: Commit of our remote ref"""
312318
returnself.ref.commit
313319

314-
@classmethod
320+
@classmethod
315321
def_from_line(cls,repo:'Repo',line:str,fetch_line:str)->'FetchInfo':
316322
"""Parse information from the given line as returned by git-fetch -v
317323
and return a new FetchInfo object representing this information.
318324
319-
We can handle a line as follows
320-
"%c %-*s %-*s -> %s%s"
325+
We can handle a line as follows:
326+
"%c %-\\*s %-\\*s -> %s%s"
321327
322-
Where c is either ' ', !, +, -, *, or =
328+
Where c is either ' ', !, +, -,\\*, or =
323329
! means error
324330
+ means success forcing update
325331
- means a tag was updated
@@ -334,6 +340,7 @@ def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo':
334340
raiseValueError("Failed to parse line: %r"%line)
335341

336342
# parse lines
343+
remote_local_ref_str:str
337344
control_character,operation,local_remote_ref,remote_local_ref_str,note=match.groups()
338345
assertis_flagKeyLiteral(control_character),f"{control_character}"
339346

@@ -375,7 +382,7 @@ def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo':
375382
# If we do not specify a target branch like master:refs/remotes/origin/master,
376383
# the fetch result is stored in FETCH_HEAD which destroys the rule we usually
377384
# have. In that case we use a symbolic reference which is detached
378-
ref_type=None
385+
ref_type:Optional[Type[SymbolicReference]]=None
379386
ifremote_local_ref_str=="FETCH_HEAD":
380387
ref_type=SymbolicReference
381388
elifref_type_name=="tag"oris_tag_operation:
@@ -404,14 +411,15 @@ def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo':
404411
# by the 'ref/' prefix. Otherwise even a tag could be in refs/remotes, which is when it will have the
405412
# 'tags/' subdirectory in its path.
406413
# We don't want to test for actual existence, but try to figure everything out analytically.
407-
ref_path=None# type: Optional[PathLike]
414+
ref_path:Optional[PathLike]=None
408415
remote_local_ref_str=remote_local_ref_str.strip()
416+
409417
ifremote_local_ref_str.startswith(Reference._common_path_default+"/"):
410418
# always use actual type if we get absolute paths
411419
# Will always be the case if something is fetched outside of refs/remotes (if its not a tag)
412420
ref_path=remote_local_ref_str
413421
ifref_typeisnotTagReferenceandnot \
414-
remote_local_ref_str.startswith(RemoteReference._common_path_default+"/"):
422+
remote_local_ref_str.startswith(RemoteReference._common_path_default+"/"):
415423
ref_type=Reference
416424
# END downgrade remote reference
417425
elifref_typeisTagReferenceand'tags/'inremote_local_ref_str:
@@ -430,6 +438,11 @@ def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo':
430438

431439
returncls(remote_local_ref,flags,note,old_commit,local_remote_ref)
432440

441+
@classmethod
442+
defiter_items(cls,repo:'Repo',*args:Any,**kwargs:Any
443+
)->NoReturn:# -> Iterator['FetchInfo']:
444+
raiseNotImplementedError
445+
433446

434447
classRemote(LazyMixin,IterableObj):
435448

@@ -507,7 +520,7 @@ def exists(self) -> bool:
507520
returnFalse
508521
# end
509522

510-
@classmethod
523+
@classmethod
511524
defiter_items(cls,repo:'Repo',*args:Any,**kwargs:Any)->Iterator['Remote']:
512525
""":return: Iterator yielding Remote objects of the given repository"""
513526
forsectioninrepo.config_reader("repository").sections():
@@ -897,7 +910,7 @@ def push(self, refspec: Union[str, List[str], None] = None,
897910
universal_newlines=True,**kwargs)
898911
returnself._get_push_info(proc,progress)
899912

900-
@property
913+
@property
901914
defconfig_reader(self)->SectionConstraint:
902915
"""
903916
:return:
@@ -912,7 +925,7 @@ def _clear_cache(self) -> None:
912925
pass
913926
# END handle exception
914927

915-
@property
928+
@property
916929
defconfig_writer(self)->SectionConstraint:
917930
"""
918931
:return: GitConfigParser compatible object able to write options for this remote.

‎git/util.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

7+
fromabcimportabstractmethod
78
from .excimportInvalidGitRepositoryError
89
importos.pathasosp
910
from .compatimportis_win
@@ -28,7 +29,8 @@
2829
# typing ---------------------------------------------------------
2930

3031
fromtypingimport (Any,AnyStr,BinaryIO,Callable,Dict,Generator,IO,Iterator,List,
31-
Optional,Pattern,Sequence,Tuple,TypeVar,Union,cast,TYPE_CHECKING,overload)
32+
Optional,Pattern,Sequence,Tuple,TypeVar,Union,cast,
33+
TYPE_CHECKING,overload, )
3234

3335
importpathlib
3436

@@ -39,8 +41,8 @@
3941
# from git.objects.base import IndexObject
4042

4143

42-
from .typesimport (Literal,SupportsIndex,# because behind py version guards
43-
PathLike,HSH_TD,Total_TD,Files_TD,# aliases
44+
from .typesimport (Literal,SupportsIndex,Protocol,runtime_checkable,# because behind py version guards
45+
PathLike,HSH_TD,Total_TD,Files_TD,# aliases
4446
Has_id_attribute)
4547

4648
T_IterableObj=TypeVar('T_IterableObj',bound=Union['IterableObj','Has_id_attribute'],covariant=True)
@@ -471,7 +473,7 @@ def _parse_progress_line(self, line: AnyStr) -> None:
471473
472474
- Lines that do not contain progress info are stored in :attr:`other_lines`.
473475
- Lines that seem to contain an error (i.e. start with error: or fatal:) are stored
474-
in :attr:`error_lines`."""
476+
in :attr:`error_lines`."""
475477
# handle
476478
# Counting objects: 4, done.
477479
# Compressing objects: 50% (1/2)
@@ -993,7 +995,7 @@ def __getattr__(self, attr: str) -> T_IterableObj:
993995
# END for each item
994996
returnlist.__getattribute__(self,attr)
995997

996-
def__getitem__(self,index:Union[SupportsIndex,int,slice,str])->'T_IterableObj':# type: ignore
998+
def__getitem__(self,index:Union[SupportsIndex,int,slice,str])->T_IterableObj:# type: ignore
997999

9981000
assertisinstance(index, (int,str,slice)),"Index of IterableList should be an int or str"
9991001

@@ -1030,23 +1032,24 @@ def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> None:
10301032

10311033

10321034
classIterableClassWatcher(type):
1035+
""" Metaclass that watches """
10331036
def__init__(cls,name,bases,clsdict):
10341037
forbaseinbases:
10351038
iftype(base)==IterableClassWatcher:
10361039
warnings.warn(f"GitPython Iterable subclassed by{name}. "
1037-
"Iterable is deprecated due to naming clash, "
1040+
"Iterable is deprecated due to naming clash since v3.1.18"
1041+
" and will be removed in 3.1.20, "
10381042
"Use IterableObj instead\n",
10391043
DeprecationWarning,
10401044
stacklevel=2)
10411045

10421046

1043-
classIterable(object):
1047+
classIterable(metaclass=IterableClassWatcher):
10441048

10451049
"""Defines an interface for iterable items which is to assure a uniform
10461050
way to retrieve and iterate items within the git repository"""
10471051
__slots__= ()
10481052
_id_attribute_="attribute that most suitably identifies your instance"
1049-
__metaclass__=IterableClassWatcher
10501053

10511054
@classmethod
10521055
deflist_items(cls,repo,*args,**kwargs):
@@ -1064,14 +1067,15 @@ def list_items(cls, repo, *args, **kwargs):
10641067
returnout_list
10651068

10661069
@classmethod
1067-
defiter_items(cls,repo:'Repo',*args:Any,**kwargs:Any):
1070+
defiter_items(cls,repo:'Repo',*args:Any,**kwargs:Any)->Any:
10681071
# return typed to be compatible with subtypes e.g. Remote
10691072
"""For more information about the arguments, see list_items
10701073
:return: iterator yielding Items"""
10711074
raiseNotImplementedError("To be implemented by Subclass")
10721075

10731076

1074-
classIterableObj():
1077+
@runtime_checkable
1078+
classIterableObj(Protocol):
10751079
"""Defines an interface for iterable items which is to assure a uniform
10761080
way to retrieve and iterate items within the git repository
10771081
@@ -1095,11 +1099,12 @@ def list_items(cls, repo: 'Repo', *args: Any, **kwargs: Any) -> IterableList[T_I
10951099
returnout_list
10961100

10971101
@classmethod
1102+
@abstractmethod
10981103
defiter_items(cls,repo:'Repo',*args:Any,**kwargs:Any
1099-
)->Iterator[T_IterableObj]:
1104+
)->Iterator[T_IterableObj]:# Iterator[T_IterableObj]:
11001105
# return typed to be compatible with subtypes e.g. Remote
11011106
"""For more information about the arguments, see list_items
1102-
:return: iterator yielding Items"""
1107+
:return: iterator yielding Items"""
11031108
raiseNotImplementedError("To be implemented by Subclass")
11041109

11051110
# } END classes

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp