Skip to content

Commit e441576

Browse files
Refine session timestamp type guards to plain types
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 98066de commit e441576

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

hyperbrowser/models/session.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,24 +144,25 @@ def parse_timestamp(cls, value: Optional[Union[str, int]]) -> Optional[int]:
144144
"""Convert string timestamps to integers."""
145145
if value is None:
146146
return None
147-
if isinstance(value, bool):
147+
value_type = type(value)
148+
if value_type is bool:
148149
raise ValueError(
149150
"timestamp values must be integers or plain numeric strings"
150151
)
151-
if type(value) is int:
152+
if value_type is int:
152153
return value
153-
if isinstance(value, int):
154+
if int in value_type.__mro__:
154155
raise ValueError(
155156
"timestamp values must be plain integers or plain numeric strings"
156157
)
157-
if type(value) is str:
158+
if value_type is str:
158159
try:
159160
return int(value)
160161
except Exception as exc:
161162
raise ValueError(
162163
"timestamp string values must be integer-formatted"
163164
) from exc
164-
if isinstance(value, str):
165+
if str in value_type.__mro__:
165166
raise ValueError("timestamp string values must be plain strings")
166167
raise ValueError(
167168
"timestamp values must be plain integers or plain numeric strings"

0 commit comments

Comments
 (0)