Skip to content

Commit 37fa31d

Browse files
authored
Merge pull request #1304 from gitpython-developers/types2
Fix orderdict, improve types
2 parents e766919 + 995547a commit 37fa31d

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

git/config.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141

4242
T_ConfigParser = TypeVar('T_ConfigParser', bound='GitConfigParser')
4343

44-
if sys.version_info[:2] < (3, 7):
45-
from collections import OrderedDict
46-
OrderedDict_OMD = OrderedDict
44+
if sys.version_info[:3] < (3, 7, 2):
45+
# typing.Ordereddict not added until py 3.7.2
46+
from collections import OrderedDict # type: ignore # until 3.6 dropped
47+
OrderedDict_OMD = OrderedDict # type: ignore # until 3.6 dropped
4748
else:
48-
from typing import OrderedDict
49-
OrderedDict_OMD = OrderedDict[str, List[_T]]
49+
from typing import OrderedDict # type: ignore # until 3.6 dropped
50+
OrderedDict_OMD = OrderedDict[str, List[_T]] # type: ignore[assignment, misc]
5051

5152
# -------------------------------------------------------------
5253

git/objects/util.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,11 @@ def list_traverse(self: T_TIobj, *args: Any, **kwargs: Any) -> IterableList[T_TI
493493
return super(TraversableIterableObj, self)._list_traverse(* args, **kwargs)
494494

495495
@ overload # type: ignore
496+
def traverse(self: T_TIobj
497+
) -> Iterator[T_TIobj]:
498+
...
499+
500+
@ overload
496501
def traverse(self: T_TIobj,
497502
predicate: Callable[[Union[T_TIobj, Tuple[Union[T_TIobj, None], T_TIobj]], int], bool],
498503
prune: Callable[[Union[T_TIobj, Tuple[Union[T_TIobj, None], T_TIobj]], int], bool],

git/refs/reference.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ def __str__(self) -> str:
6262

6363
#{ Interface
6464

65-
def set_object(self, object: Commit_ish, logmsg: Union[str, None] = None) -> 'Reference': # @ReservedAssignment
65+
# @ReservedAssignment
66+
def set_object(self, object: Union[Commit_ish, 'SymbolicReference'], logmsg: Union[str, None] = None
67+
) -> 'SymbolicReference':
6668
"""Special version which checks if the head-log needs an update as well
6769
:return: self"""
6870
oldbinsha = None

git/refs/tag.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
# typing ------------------------------------------------------------------
66

7-
from typing import Any, Union, TYPE_CHECKING
7+
from typing import Any, Type, Union, TYPE_CHECKING
88
from git.types import Commit_ish, PathLike
99

1010
if TYPE_CHECKING:
1111
from git.repo import Repo
1212
from git.objects import Commit
1313
from git.objects import TagObject
14+
from git.refs import SymbolicReference
1415

1516

1617
# ------------------------------------------------------------------------------
@@ -68,7 +69,8 @@ def object(self) -> Commit_ish: # type: ignore[override]
6869
return Reference._get_object(self)
6970

7071
@classmethod
71-
def create(cls, repo: 'Repo', path: PathLike, reference: Union[Commit_ish, str] = 'HEAD',
72+
def create(cls: Type['TagReference'], repo: 'Repo', path: PathLike,
73+
reference: Union[str, 'SymbolicReference'] = 'HEAD',
7274
logmsg: Union[str, None] = None,
7375
force: bool = False, **kwargs: Any) -> 'TagReference':
7476
"""Create a new tag reference.
@@ -78,7 +80,7 @@ def create(cls, repo: 'Repo', path: PathLike, reference: Union[Commit_ish, str]
7880
The prefix refs/tags is implied
7981
8082
:param ref:
81-
A reference to the object you want to tag. It can be a commit, tree or
83+
A reference to the Object you want to tag. The Object can be a commit, tree or
8284
blob.
8385
8486
:param logmsg:
@@ -98,7 +100,9 @@ def create(cls, repo: 'Repo', path: PathLike, reference: Union[Commit_ish, str]
98100
Additional keyword arguments to be passed to git-tag
99101
100102
:return: A new TagReference"""
101-
args = (path, reference)
103+
if 'ref' in kwargs and kwargs['ref']:
104+
reference = kwargs['ref']
105+
102106
if logmsg:
103107
kwargs['m'] = logmsg
104108
elif 'message' in kwargs and kwargs['message']:
@@ -107,11 +111,13 @@ def create(cls, repo: 'Repo', path: PathLike, reference: Union[Commit_ish, str]
107111
if force:
108112
kwargs['f'] = True
109113

114+
args = (path, reference)
115+
110116
repo.git.tag(*args, **kwargs)
111117
return TagReference(repo, "%s/%s" % (cls._common_path_default, path))
112118

113119
@classmethod
114-
def delete(cls, repo: 'Repo', *tags: 'TagReference') -> None:
120+
def delete(cls, repo: 'Repo', *tags: 'TagReference') -> None: # type: ignore[override]
115121
"""Delete the given existing tag or tags"""
116122
repo.git.tag("-d", *tags)
117123

git/repo/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,14 @@ def _to_full_tag_path(path):
422422

423423
def create_head(self, path: PathLike, commit: str = 'HEAD',
424424
force: bool = False, logmsg: Optional[str] = None
425-
) -> Head:
425+
) -> 'Head':
426426
"""Create a new head within the repository.
427427
For more documentation, please see the Head.create method.
428428
429429
:return: newly created Head Reference"""
430430
return Head.create(self, path, commit, logmsg, force)
431431

432-
def delete_head(self, *heads: 'SymbolicReference', **kwargs: Any) -> None:
432+
def delete_head(self, *heads: 'Head', **kwargs: Any) -> None:
433433
"""Delete the given heads
434434
435435
:param kwargs: Additional keyword arguments to be passed to git-branch"""
@@ -788,10 +788,10 @@ def ignored(self, *paths: PathLike) -> List[PathLike]:
788788
return proc.replace("\\\\", "\\").replace('"', "").split("\n")
789789

790790
@property
791-
def active_branch(self) -> 'SymbolicReference':
791+
def active_branch(self) -> Head:
792792
"""The name of the currently active branch.
793-
794793
:return: Head to the active branch"""
794+
# reveal_type(self.head.reference) # => Reference
795795
return self.head.reference
796796

797797
def blame_incremental(self, rev: TBD, file: TBD, **kwargs: Any) -> Optional[Iterator['BlameEntry']]:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy