Skip to content

More types for symbolic.py #1307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jul 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3347c00
change ordereddict guard, add type: ignore
Yobmod Jul 28, 2021
77a7769
Merge branch 'main' of https://github.com/Yobmod/GitPython
Yobmod Jul 28, 2021
28fdd30
Fix SymbolicReference reference typing
Yobmod Jul 28, 2021
3abc837
Add another type ignore for Ordereddict
Yobmod Jul 28, 2021
6791424
Rmv py 3.10 check for typing.Ordereddict - its deprecated then, but w…
Yobmod Jul 28, 2021
c464e33
Fix some SymbolicReference types
Yobmod Jul 28, 2021
7cf30c1
Fix forwardref
Yobmod Jul 28, 2021
5b880c0
Fix more missing types in Symbolic.py
Yobmod Jul 28, 2021
07d71e5
Fix more missing types in Symbolic.py
Yobmod Jul 28, 2021
b8b07b9
Fix more missing types in Symbolic.py.
Yobmod Jul 28, 2021
390efbf
Fix more missing types in Symbolic.py, cos GuthubActions pytest stuck
Yobmod Jul 28, 2021
070f5c0
Rmv test file
Yobmod Jul 28, 2021
adc00dd
Fix more missing types in Symbolic.py, cos GuthubActions pytest stuck
Yobmod Jul 28, 2021
28251c3
Try downgrading pip
Yobmod Jul 28, 2021
dbb689b
its not pip...
Yobmod Jul 28, 2021
cf29514
try https://github.com/actions/virtual-environments/issues/709 workar…
Yobmod Jul 28, 2021
f1e6e8d
Merge branch 'main' of https://github.com/Yobmod/GitPython
Yobmod Jul 31, 2021
15d1c01
Add type to symbolicreference.name()
Yobmod Jul 31, 2021
34e9850
Add type to symbolicreference.iter_items()
Yobmod Jul 31, 2021
265d40b
Add type to symbolicreference.rename()
Yobmod Jul 31, 2021
bdd6a43
Add type to symbolicreference.__repr__()
Yobmod Jul 31, 2021
1f92267
Add type to symbolicreference._get_ref_info()
Yobmod Jul 31, 2021
ad4517f
Add type to symbolicreference._get_packed_refs_path()
Yobmod Jul 31, 2021
6b0faba
Add type to symbolicreference.dereference_recursive()
Yobmod Jul 31, 2021
7e972b9
Add type to symbolicreference.dereference_recursive()
Yobmod Jul 31, 2021
24c1242
Add type to symbolicreference()
Yobmod Jul 31, 2021
8eedc9d
Add type to symbolicreference.get_()
Yobmod Jul 31, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix more missing types in Symbolic.py
  • Loading branch information
Yobmod committed Jul 28, 2021
commit 5b880c0e98e41276de9fc498b25727c149cfcc40
22 changes: 13 additions & 9 deletions git/refs/symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

if TYPE_CHECKING:
from git.repo import Repo
from git.refs import Reference
from git.refs import Reference, Head, HEAD, TagReference, RemoteReference

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

Expand Down Expand Up @@ -141,13 +141,13 @@ def dereference_recursive(cls, repo: 'Repo', ref_path: PathLike) -> str:
intermediate references as required
:param repo: the repository containing the reference at ref_path"""
while True:
hexsha, ref_path = cls._get_ref_info(repo, ref_path)
hexsha, _ref_path_out = cls._get_ref_info(repo, ref_path)
if hexsha is not None:
return hexsha
# END recursive dereferencing

@classmethod
def _get_ref_info_helper(cls, repo: 'Repo', ref_path: PathLike):
def _get_ref_info_helper(cls, repo: 'Repo', ref_path: PathLike) -> Union[Tuple[str, None], Tuple[None, PathLike]]:
"""Return: (str(sha), str(target_ref_path)) if available, the sha the file at
rela_path points to, or None. target_ref_path is the reference we
point to, or None"""
Expand Down Expand Up @@ -186,13 +186,14 @@ def _get_ref_info_helper(cls, repo: 'Repo', ref_path: PathLike):
raise ValueError("Failed to parse reference information from %r" % ref_path)

@classmethod
def _get_ref_info(cls, repo: 'Repo', ref_path: PathLike):
def _get_ref_info(cls, repo: 'Repo', ref_path: PathLike
) -> Union[Tuple[str, None], Tuple[None, PathLike]]:
"""Return: (str(sha), str(target_ref_path)) if available, the sha the file at
rela_path points to, or None. target_ref_path is the reference we
point to, or None"""
return cls._get_ref_info_helper(repo, ref_path)

def _get_object(self):
def _get_object(self) -> Commit_ish:
"""
:return:
The object our ref currently refers to. Refs can be cached, they will
Expand All @@ -201,7 +202,7 @@ def _get_object(self):
# Our path will be resolved to the hexsha which will be used accordingly
return Object.new_from_sha(self.repo, hex_to_bin(self.dereference_recursive(self.repo, self.path)))

def _get_commit(self):
def _get_commit(self) -> 'Commit':
"""
:return:
Commit object we point to, works for detached and non-detached
Expand All @@ -216,7 +217,8 @@ def _get_commit(self):
# END handle type
return obj

def set_commit(self, commit: Union[Commit, 'SymbolicReference', str], logmsg=None):
def set_commit(self, commit: Union[Commit, 'SymbolicReference', str],
logmsg: Union[str, None] = None) -> None:
"""As set_object, but restricts the type of object to be a Commit

:raise ValueError: If commit is not a Commit object or doesn't point to
Expand All @@ -243,7 +245,8 @@ def set_commit(self, commit: Union[Commit, 'SymbolicReference', str], logmsg=Non
# we leave strings to the rev-parse method below
self.set_object(commit, logmsg)

return self
# return self
return None

def set_object(self, object, logmsg=None): # @ReservedAssignment
"""Set the object we point to, possibly dereference our symbolic reference first.
Expand Down Expand Up @@ -275,7 +278,8 @@ def set_object(self, object, logmsg=None): # @ReservedAssignment
commit = property(_get_commit, set_commit, doc="Query or set commits directly")
object = property(_get_object, set_object, doc="Return the object our ref currently refers to")

def _get_reference(self):
def _get_reference(self
) -> Union['HEAD', 'Head', 'RemoteReference', 'TagReference', 'Reference', 'SymbolicReference']:
""":return: Reference Object we point to
:raise TypeError: If this symbolic reference is detached, hence it doesn't point
to a reference, but to a commit"""
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ filterwarnings = 'ignore::DeprecationWarning'
# filterwarnings ignore::WarningType # ignores those warnings

[tool.mypy]
# disallow_untyped_defs = True
# disallow_untyped_defs = true
no_implicit_optional = true
warn_redundant_casts = true
# warn_unused_ignores = True
# warn_unreachable = True
# warn_unused_ignores = true
# warn_unreachable = true
show_error_codes = true

# TODO: remove when 'gitdb' is fully annotated
Expand Down