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

Commitdc6b90f

Browse files
committed
Fix version_info type hint + more refactoring
This broadens the type annoation on the Git.version_info property,for#1830.It also revises the docstring for clarity, and continuesrefactoring and comment changes (also for clarity).
1 parenteb438ee commitdc6b90f

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

‎git/cmd.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ def __init__(self, working_dir: Union[None, PathLike] = None):
794794
self._environment:Dict[str,str]= {}
795795

796796
# Cached version slots
797-
self._version_info:Union[Tuple[int,int,int,int],None]=None
797+
self._version_info:Union[Tuple[int,...],None]=None
798798
self._version_info_token:object=None
799799

800800
# Cached command slots
@@ -831,10 +831,10 @@ def working_dir(self) -> Union[None, PathLike]:
831831
returnself._working_dir
832832

833833
@property
834-
defversion_info(self)->Tuple[int,int,int,int]:
834+
defversion_info(self)->Tuple[int,...]:
835835
"""
836-
:return:tuple(int, int, int, int)tuple with integers representing the major,
837-
minor and additionalversion numbers as parsed from git version.
836+
:return:tuple with integers representing the major, minor and additional
837+
version numbers as parsed from git version. Up to four fields are used.
838838
839839
This value is generated on demand and is cached.
840840
"""
@@ -846,16 +846,14 @@ def version_info(self) -> Tuple[int, int, int, int]:
846846
assertself._version_infoisnotNone,"Bug: corrupted token-check state"
847847
returnself._version_info
848848

849-
# We only use the first 4 numbers, as everything else could be strings in fact (on Windows).
850-
process_version=self._call_process("version")# Should be as default *args and **kwargs used.
851-
version_numbers=process_version.split(" ")[2]
849+
# Run "git version" and parse it.
850+
process_version=self._call_process("version")
851+
version_string=process_version.split(" ")[2]
852+
version_fields=version_string.split(".")[:4]
853+
self._version_info=tuple(int(n)forninversion_fieldsifn.isdigit())
852854

853-
self._version_info=cast(
854-
Tuple[int,int,int,int],
855-
tuple(int(n)forninversion_numbers.split(".")[:4]ifn.isdigit()),
856-
)
855+
# This value will be considered valid until the next refresh.
857856
self._version_info_token=refresh_token
858-
859857
returnself._version_info
860858

861859
@overload

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp