Skip to content
This repository was archived by the owner on Sep 2, 2023. It is now read-only.

Commit 42c468e

Browse files
committed
fix internal typing errors (public api unchanged); add mypy to pipeline
1 parent 0203d38 commit 42c468e

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

.github/workflows/python.yml

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ jobs:
9393
# > tests/resources/__init__.py:1:0: F0010: error while code parsing: Unable to load file tests/resources/__init__.py:
9494
# > [Errno 2] No such file or directory: 'tests/resources/__init__.py' (parse-error)
9595
- run: pipenv run pylint --disable=parse-error tests/*
96+
- run: pipenv run mypy "$(cat *.egg-info/top_level.txt)" tests
9697
# >=1.9.0 to detect branch name
9798
# https://github.com/coveralls-clients/coveralls-python/pull/207
9899
# https://github.com/coverallsapp/github-action/issues/4#issuecomment-547036866

freesurfer_stats/__init__.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(self):
9797

9898
@property
9999
def hemisphere(self) -> str:
100-
return self._HEMISPHERE_PREFIX_TO_SIDE[self.headers["hemi"]]
100+
return self._HEMISPHERE_PREFIX_TO_SIDE[typing.cast(str, self.headers["hemi"])]
101101

102102
@staticmethod
103103
def _read_header_line(stream: typing.TextIO) -> str:
@@ -122,26 +122,31 @@ def _read_headers(self, stream: typing.TextIO) -> None:
122122
if line.startswith("Measure"):
123123
break
124124
if line:
125-
attr_name, attr_value = line.split(" ", maxsplit=1)
126-
attr_value = attr_value.lstrip()
125+
attr_name, attr_value_str = line.split(" ", maxsplit=1)
126+
attr_value_str = attr_value_str.lstrip()
127127
if attr_name in ["cvs_version", "mrisurf.c-cvs_version"]:
128-
attr_value = attr_value.strip("$").rstrip()
129-
if attr_name == "CreationTime":
128+
attr_value = typing.cast(
129+
typing.Union[str, datetime.datetime],
130+
attr_value_str.strip("$").rstrip(),
131+
)
132+
elif attr_name == "CreationTime":
130133
attr_dt = datetime.datetime.strptime(
131-
attr_value, "%Y/%m/%d-%H:%M:%S-%Z"
134+
attr_value_str, "%Y/%m/%d-%H:%M:%S-%Z"
132135
)
133136
if attr_dt.tzinfo is None:
134-
assert attr_value.endswith("-GMT")
137+
assert attr_value_str.endswith("-GMT")
135138
attr_dt = attr_dt.replace(tzinfo=datetime.timezone.utc)
136139
attr_value = attr_dt
137-
if attr_name == "AnnotationFileTimeStamp":
140+
elif attr_name == "AnnotationFileTimeStamp":
138141
attr_value = datetime.datetime.strptime(
139-
attr_value, "%Y/%m/%d %H:%M:%S"
142+
attr_value_str, "%Y/%m/%d %H:%M:%S"
140143
)
144+
else:
145+
attr_value = attr_value_str
141146
self.headers[attr_name] = attr_value
142147

143148
@classmethod
144-
def _format_column_name(cls, name: str, unit: typing.Optional[str]) -> str:
149+
def _format_column_name(cls, name: str, unit: str) -> str:
145150
column_name = name.lower()
146151
if unit not in ["unitless", "NA"]:
147152
column_name += "_" + unit
@@ -169,7 +174,7 @@ def _read_column_attributes(
169174
) -> typing.List[typing.Dict[str, str]]:
170175
columns = []
171176
for column_index in range(1, int(num) + 1):
172-
column_attrs = {}
177+
column_attrs = {} # type: typing.Dict[str, str]
173178
for _ in range(3):
174179
column_index_line, key, value = cls._read_column_header_line(stream)
175180
assert column_index_line == column_index

0 commit comments

Comments
 (0)