Skip to content

Commit a024bdd

Browse files
committed
Move TraverseNT to global, cos mypy complained on testing
1 parent 3c6deb0 commit a024bdd

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

‎git/objects/submodule/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No
425425
raise ValueError("A URL was not given and a repository did not exist at %s" % path)
426426
# END check url
427427
mrepo = sm.module()
428+
assert isinstance(mrepo, Repo)
428429
urls = [r.url for r in mrepo.remotes]
429430
if not urls:
430431
raise ValueError("Didn't find any remote url in repository at %s" % sm.abspath)

‎git/objects/util.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
from .submodule.base import Submodule
3636

3737

38+
class TraverseNT(NamedTuple):
39+
depth: int
40+
item: Union['Traversable', 'Blob']
41+
src: Union['Traversable', None]
42+
43+
3844
T_TIobj = TypeVar('T_TIobj', bound='TraversableIterableObj') # for TraversableIterableObj.traverse()
3945

4046
TraversedTup = Union[Tuple[Union['Traversable', None], 'Traversable'], # for commit, submodule
@@ -379,10 +385,6 @@ def traverse(self,
379385
ignore_self=True is_edge=False --> Iterator[item]
380386
ignore_self=False is_edge=True -> Iterator[item] | Iterator[Tuple[src, item]]
381387
ignore_self=False is_edge=False -> Iterator[Tuple[src, item]]"""
382-
class TraverseNT(NamedTuple):
383-
depth: int
384-
item: Union['Traversable', 'Blob']
385-
src: Union['Traversable', None]
386388

387389
visited = set()
388390
stack = deque() # type: Deque[TraverseNT]

‎git/util.py

+17-16
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@
3636
from git.remote import Remote
3737
from git.repo.base import Repo
3838
from git.config import GitConfigParser, SectionConstraint
39-
from git.objects.base import IndexObject
39+
# from git.objects.base import IndexObject
4040

4141

4242
from .types import (Literal, SupportsIndex, # because behind py version guards
43-
PathLike, HSH_TD, Total_TD, Files_TD) # aliases
43+
PathLike, HSH_TD, Total_TD, Files_TD, # aliases
44+
Has_id_attribute)
4445

45-
T_IterableObj = TypeVar('T_IterableObj', bound=Union['IterableObj', 'IndexObject'], covariant=True)
46+
T_IterableObj = TypeVar('T_IterableObj', bound=Union['IterableObj', 'Has_id_attribute'], covariant=True)
4647
# So IterableList[Head] is subtype of IterableList[IterableObj]
4748

4849
# ---------------------------------------------------------------------
@@ -82,7 +83,7 @@
8283
HIDE_WINDOWS_KNOWN_ERRORS = is_win and os.environ.get('HIDE_WINDOWS_KNOWN_ERRORS', True)
8384
HIDE_WINDOWS_FREEZE_ERRORS = is_win and os.environ.get('HIDE_WINDOWS_FREEZE_ERRORS', True)
8485

85-
#{ Utility Methods
86+
# { Utility Methods
8687

8788
T = TypeVar('T')
8889

@@ -247,7 +248,7 @@ def is_exec(fpath: str) -> bool:
247248

248249
def _cygexpath(drive: Optional[str], path: str) -> str:
249250
if osp.isabs(path) and not drive:
250-
## Invoked from `cygpath()` directly with `D:Apps\123`?
251+
# Invoked from `cygpath()` directly with `D:Apps\123`?
251252
# It's an error, leave it alone just slashes)
252253
p = path # convert to str if AnyPath given
253254
else:
@@ -265,8 +266,8 @@ def _cygexpath(drive: Optional[str], path: str) -> str:
265266

266267

267268
_cygpath_parsers = (
268-
## See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
269-
## and: https://www.cygwin.com/cygwin-ug-net/using.html#unc-paths
269+
# See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
270+
# and: https://www.cygwin.com/cygwin-ug-net/using.html#unc-paths
270271
(re.compile(r"\\\\\?\\UNC\\([^\\]+)\\([^\\]+)(?:\\(.*))?"),
271272
(lambda server, share, rest_path: '//%s/%s/%s' % (server, share, rest_path.replace('\\', '/'))),
272273
False
@@ -297,7 +298,7 @@ def _cygexpath(drive: Optional[str], path: str) -> str:
297298
def cygpath(path: str) -> str:
298299
"""Use :meth:`git.cmd.Git.polish_url()` instead, that works on any environment."""
299300
path = str(path) # ensure is str and not AnyPath.
300-
#Fix to use Paths when 3.5 dropped. or to be just str if only for urls?
301+
# Fix to use Paths when 3.5 dropped. or to be just str if only for urls?
301302
if not path.startswith(('/cygdrive', '//')):
302303
for regex, parser, recurse in _cygpath_parsers:
303304
match = regex.match(path)
@@ -357,7 +358,7 @@ def is_cygwin_git(git_executable: Union[None, PathLike]) -> bool:
357358
res = py_where(git_executable)
358359
git_dir = osp.dirname(res[0]) if res else ""
359360

360-
## Just a name given, not a real path.
361+
# Just a name given, not a real path.
361362
uname_cmd = osp.join(git_dir, 'uname')
362363
process = subprocess.Popen([uname_cmd], stdout=subprocess.PIPE,
363364
universal_newlines=True)
@@ -378,7 +379,7 @@ def get_user_id() -> str:
378379

379380
def finalize_process(proc: subprocess.Popen, **kwargs: Any) -> None:
380381
"""Wait for the process (clone, fetch, pull or push) and handle its errors accordingly"""
381-
## TODO: No close proc-streams??
382+
# TODO: No close proc-streams??
382383
proc.wait(**kwargs)
383384

384385

@@ -432,9 +433,9 @@ def remove_password_if_present(cmdline):
432433
return new_cmdline
433434

434435

435-
#} END utilities
436+
# } END utilities
436437

437-
#{ Classes
438+
# { Classes
438439

439440

440441
class RemoteProgress(object):
@@ -984,15 +985,15 @@ def __contains__(self, attr: object) -> bool:
984985
return False
985986
# END handle membership
986987

987-
def __getattr__(self, attr: str) -> Any:
988+
def __getattr__(self, attr: str) -> T_IterableObj:
988989
attr = self._prefix + attr
989990
for item in self:
990991
if getattr(item, self._id_attr) == attr:
991992
return item
992993
# END for each item
993994
return list.__getattribute__(self, attr)
994995

995-
def __getitem__(self, index: Union[SupportsIndex, int, slice, str]) -> Any:
996+
def __getitem__(self, index: Union[SupportsIndex, int, slice, str]) -> 'T_IterableObj': # type: ignore
996997

997998
assert isinstance(index, (int, str, slice)), "Index of IterableList should be an int or str"
998999

@@ -1007,7 +1008,7 @@ def __getitem__(self, index: Union[SupportsIndex, int, slice, str]) -> Any:
10071008
raise IndexError("No item found with id %r" % (self._prefix + index)) from e
10081009
# END handle getattr
10091010

1010-
def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> Any:
1011+
def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> None:
10111012

10121013
assert isinstance(index, (int, str)), "Index of IterableList should be an int or str"
10131014

@@ -1101,7 +1102,7 @@ def iter_items(cls, repo: 'Repo', *args: Any, **kwargs: Any
11011102
:return: iterator yielding Items"""
11021103
raise NotImplementedError("To be implemented by Subclass")
11031104

1104-
#} END classes
1105+
# } END classes
11051106

11061107

11071108
class NullHandler(logging.Handler):

0 commit comments

Comments
 (0)