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

Commit

Permalink
fix internal typing errors (public api unchanged); add mypy to pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
fphammerle committed Dec 31, 2020
1 parent 0203d38 commit 42c468e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ jobs:
# > tests/resources/__init__.py:1:0: F0010: error while code parsing: Unable to load file tests/resources/__init__.py:
# > [Errno 2] No such file or directory: 'tests/resources/__init__.py' (parse-error)
- run: pipenv run pylint --disable=parse-error tests/*
- run: pipenv run mypy "$(cat *.egg-info/top_level.txt)" tests
# >=1.9.0 to detect branch name
# https://github.com/coveralls-clients/coveralls-python/pull/207
# https://github.com/coverallsapp/github-action/issues/4#issuecomment-547036866
Expand Down
27 changes: 16 additions & 11 deletions freesurfer_stats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(self):

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

@staticmethod
def _read_header_line(stream: typing.TextIO) -> str:
Expand All @@ -122,26 +122,31 @@ def _read_headers(self, stream: typing.TextIO) -> None:
if line.startswith("Measure"):
break
if line:
attr_name, attr_value = line.split(" ", maxsplit=1)
attr_value = attr_value.lstrip()
attr_name, attr_value_str = line.split(" ", maxsplit=1)
attr_value_str = attr_value_str.lstrip()
if attr_name in ["cvs_version", "mrisurf.c-cvs_version"]:
attr_value = attr_value.strip("$").rstrip()
if attr_name == "CreationTime":
attr_value = typing.cast(
typing.Union[str, datetime.datetime],
attr_value_str.strip("$").rstrip(),
)
elif attr_name == "CreationTime":
attr_dt = datetime.datetime.strptime(
attr_value, "%Y/%m/%d-%H:%M:%S-%Z"
attr_value_str, "%Y/%m/%d-%H:%M:%S-%Z"
)
if attr_dt.tzinfo is None:
assert attr_value.endswith("-GMT")
assert attr_value_str.endswith("-GMT")
attr_dt = attr_dt.replace(tzinfo=datetime.timezone.utc)
attr_value = attr_dt
if attr_name == "AnnotationFileTimeStamp":
elif attr_name == "AnnotationFileTimeStamp":
attr_value = datetime.datetime.strptime(
attr_value, "%Y/%m/%d %H:%M:%S"
attr_value_str, "%Y/%m/%d %H:%M:%S"
)
else:
attr_value = attr_value_str
self.headers[attr_name] = attr_value

@classmethod
def _format_column_name(cls, name: str, unit: typing.Optional[str]) -> str:
def _format_column_name(cls, name: str, unit: str) -> str:
column_name = name.lower()
if unit not in ["unitless", "NA"]:
column_name += "_" + unit
Expand Down Expand Up @@ -169,7 +174,7 @@ def _read_column_attributes(
) -> typing.List[typing.Dict[str, str]]:
columns = []
for column_index in range(1, int(num) + 1):
column_attrs = {}
column_attrs = {} # type: typing.Dict[str, str]
for _ in range(3):
column_index_line, key, value = cls._read_column_header_line(stream)
assert column_index_line == column_index
Expand Down

0 comments on commit 42c468e

Please sign in to comment.