@@ -97,7 +97,7 @@ def __init__(self):
97
97
98
98
@property
99
99
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" ]) ]
101
101
102
102
@staticmethod
103
103
def _read_header_line (stream : typing .TextIO ) -> str :
@@ -122,26 +122,31 @@ def _read_headers(self, stream: typing.TextIO) -> None:
122
122
if line .startswith ("Measure" ):
123
123
break
124
124
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 ()
127
127
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" :
130
133
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"
132
135
)
133
136
if attr_dt .tzinfo is None :
134
- assert attr_value .endswith ("-GMT" )
137
+ assert attr_value_str .endswith ("-GMT" )
135
138
attr_dt = attr_dt .replace (tzinfo = datetime .timezone .utc )
136
139
attr_value = attr_dt
137
- if attr_name == "AnnotationFileTimeStamp" :
140
+ elif attr_name == "AnnotationFileTimeStamp" :
138
141
attr_value = datetime .datetime .strptime (
139
- attr_value , "%Y/%m/%d %H:%M:%S"
142
+ attr_value_str , "%Y/%m/%d %H:%M:%S"
140
143
)
144
+ else :
145
+ attr_value = attr_value_str
141
146
self .headers [attr_name ] = attr_value
142
147
143
148
@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 :
145
150
column_name = name .lower ()
146
151
if unit not in ["unitless" , "NA" ]:
147
152
column_name += "_" + unit
@@ -169,7 +174,7 @@ def _read_column_attributes(
169
174
) -> typing .List [typing .Dict [str , str ]]:
170
175
columns = []
171
176
for column_index in range (1 , int (num ) + 1 ):
172
- column_attrs = {}
177
+ column_attrs = {} # type: typing.Dict[str, str]
173
178
for _ in range (3 ):
174
179
column_index_line , key , value = cls ._read_column_header_line (stream )
175
180
assert column_index_line == column_index
0 commit comments