Skip to content

Commit eb438ee

Browse files
committed
Refactor and further clarify comments
+ Put assertion only on the branch where mypy benefits from it.
1 parent 82b0a1e commit eb438ee

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

git/cmd.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -833,28 +833,29 @@ def working_dir(self) -> Union[None, PathLike]:
833833
@property
834834
def version_info(self) -> Tuple[int, int, int, int]:
835835
"""
836-
:return: tuple(int, int, int, int) tuple with integers representing the major, minor
837-
and additional version numbers as parsed from git version.
836+
:return: tuple(int, int, int, int) tuple with integers representing the major,
837+
minor and additional version numbers as parsed from git version.
838838
839839
This value is generated on demand and is cached.
840840
"""
841-
# Use a copy of this global state, in case of a concurrent refresh.
842-
refresh_token = self._refresh_token
843-
844-
# Ask git for its version if we haven't done so since the last refresh.
845-
# (Refreshing is global, but version_info caching is per-instance.)
846-
if self._version_info_token is not refresh_token:
847-
# We only use the first 4 numbers, as everything else could be strings in fact (on Windows).
848-
process_version = self._call_process("version") # Should be as default *args and **kwargs used.
849-
version_numbers = process_version.split(" ")[2]
850-
851-
self._version_info = cast(
852-
Tuple[int, int, int, int],
853-
tuple(int(n) for n in version_numbers.split(".")[:4] if n.isdigit()),
854-
)
855-
self._version_info_token = refresh_token
841+
# Refreshing is global, but version_info caching is per-instance.
842+
refresh_token = self._refresh_token # Copy token in case of concurrent refresh.
843+
844+
# Use the cached version if obtained after the most recent refresh.
845+
if self._version_info_token is refresh_token:
846+
assert self._version_info is not None, "Bug: corrupted token-check state"
847+
return self._version_info
848+
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]
852+
853+
self._version_info = cast(
854+
Tuple[int, int, int, int],
855+
tuple(int(n) for n in version_numbers.split(".")[:4] if n.isdigit()),
856+
)
857+
self._version_info_token = refresh_token
856858

857-
assert self._version_info is not None, "Bug: token check should never let None through"
858859
return self._version_info
859860

860861
@overload

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