Skip to content

Commit b93a626

Browse files
committed
Tweaked AST to correct for pyserde issues
Changed AST representation to avoid using collections that contain Optional values per yukinarit/pyserde#329.
1 parent 01d3f18 commit b93a626

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

yass/ast.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
An AST.
33
"""
44

5-
from typing import TypeAlias, NewType
5+
from typing import TypeAlias, NewType, Literal
66
import enum
77
import datetime
88
import dataclasses
@@ -15,6 +15,7 @@ class StopPart(enum.Enum):
1515
A part of a Stop (e.g. Gleason Circle *Arrival*).
1616
"""
1717

18+
NONE = "none"
1819
ARRIVAL = "arrival"
1920
DEPARTURE = "departure"
2021

@@ -23,8 +24,8 @@ class StopPart(enum.Enum):
2324
StopIdx = NewType("StopIdx", int)
2425

2526

26-
TimeTableColumn: TypeAlias = tuple[StopIdx, StopPart | None]
27-
TimeTableCell: TypeAlias = datetime.time | None
27+
TimeTableColumn: TypeAlias = tuple[StopIdx, StopPart]
28+
TimeTableCell: TypeAlias = datetime.time | Literal["none"]
2829

2930

3031
@serde.serde

yass/parse.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def _route(s_route: ScrapedRoute) -> Route:
135135
LAST_WORD_RE = re.compile("(.*) (.*)$")
136136

137137

138-
def _stop(s_time_table_col: ScrapedTimeTableColumn) -> tuple[Stop, StopPart | None]:
138+
def _stop(s_time_table_col: ScrapedTimeTableColumn) -> tuple[Stop, StopPart]:
139139
last_match = LAST_WORD_RE.match(s_time_table_col)
140140
last = last_match[2] if last_match is not None else None
141141

@@ -147,7 +147,7 @@ def _stop(s_time_table_col: ScrapedTimeTableColumn) -> tuple[Stop, StopPart | No
147147
assert last_match is not None
148148
stop = last_match[1].strip()
149149
except ValueError:
150-
stop_part = None
150+
stop_part = StopPart("none")
151151
stop = s_time_table_col
152152

153153
return (stop, stop_part)
@@ -178,7 +178,7 @@ def _time_table_n_stop(
178178

179179
def _time_table_cell(s_time_table_cell: ScrapedTimeTableCell) -> TimeTableCell:
180180
if s_time_table_cell is None:
181-
return None
181+
return "none"
182182

183183
date_time = datetime.datetime.strptime(s_time_table_cell, RAW_CELL_TIME_FORMAT)
184184
return date_time.time()

0 commit comments

Comments
 (0)