Skip to content

Commit 9c86827

Browse files
committed
fix mypy issues for adaptive/_version.py
1 parent bb3d419 commit 9c86827

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

adaptive/_version.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,19 @@
2929

3030
def get_version(version_file: str = STATIC_VERSION_FILE) -> str:
3131
version_info = get_static_version_info(version_file)
32-
version = version_info["version"]
33-
if version == "__use_git__":
32+
if version_info["version"] == "__use_git__":
3433
version = get_version_from_git()
3534
if not version:
3635
version = get_version_from_git_archive(version_info)
3736
if not version:
3837
version = Version("unknown", None, None)
3938
return pep440_format(version)
4039
else:
41-
return version
40+
return version_info["version"]
4241

4342

4443
def get_static_version_info(version_file: str = STATIC_VERSION_FILE) -> Dict[str, str]:
45-
version_info = {}
44+
version_info: Dict[str, str] = {}
4645
with open(os.path.join(package_root, version_file), "rb") as f:
4746
exec(f.read(), {}, version_info)
4847
return version_info
@@ -78,32 +77,32 @@ def get_version_from_git() -> Version:
7877
stderr=subprocess.PIPE,
7978
)
8079
except OSError:
81-
return
80+
return None
8281
if p.wait() != 0:
83-
return
82+
return None
8483
if not os.path.samefile(p.communicate()[0].decode().rstrip("\n"), distr_root):
8584
# The top-level directory of the current Git repository is not the same
8685
# as the root directory of the distribution: do not extract the
8786
# version from Git.
88-
return
87+
return None
8988

9089
# git describe --first-parent does not take into account tags from branches
9190
# that were merged-in. The '--long' flag gets us the 'dev' version and
9291
# git hash, '--always' returns the git hash even if there are no tags.
9392
for opts in [["--first-parent"], []]:
9493
try:
9594
p = subprocess.Popen(
96-
["git", "describe", "--long", "--always"] + opts,
95+
["git", "describe", "--long", "--always"] + opts, # type: ignore
9796
cwd=distr_root,
9897
stdout=subprocess.PIPE,
9998
stderr=subprocess.PIPE,
10099
)
101100
except OSError:
102-
return
101+
return None
103102
if p.wait() == 0:
104103
break
105104
else:
106-
return
105+
return None
107106

108107
description = (
109108
p.communicate()[0]
@@ -143,7 +142,7 @@ def get_version_from_git() -> Version:
143142
# Currently we can only tell the tag the current commit is
144143
# pointing to, or its hash (with no version info)
145144
# if it is not tagged.
146-
def get_version_from_git_archive(version_info):
145+
def get_version_from_git_archive(version_info) -> Version:
147146
try:
148147
refnames = version_info["refnames"]
149148
git_hash = version_info["git_hash"]
@@ -166,7 +165,7 @@ def get_version_from_git_archive(version_info):
166165
return Version("unknown", dev=None, labels=[f"g{git_hash}"])
167166

168167

169-
__version__ = get_version()
168+
__version__: str = get_version()
170169

171170

172171
# The following section defines a module global 'cmdclass',

0 commit comments

Comments
 (0)