Skip to content

Commit 93aae3a

Browse files
committed
type fixes
1 parent 54c0978 commit 93aae3a

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/pyff/utils.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,18 @@ def with_tree(elt, cb):
361361

362362
def duration2timedelta(period: str) -> Optional[timedelta]:
363363
regex = re.compile(
364-
'(?P<sign>[-+]?)P(?:(?P<years>\d+)[Yy])?(?:(?P<months>\d+)[Mm])?(?:(?P<days>\d+)[Dd])?(?:T(?:(?P<hours>\d+)[Hh])?(?:(?P<minutes>\d+)[Mm])?(?:(?P<seconds>\d+)[Ss])?)?'
364+
r'(?P<sign>[-+]?)'
365+
r'P(?:(?P<years>\d+)[Yy])?(?:(?P<months>\d+)[Mm])?(?:(?P<days>\d+)[Dd])?'
366+
r'(?:T(?:(?P<hours>\d+)[Hh])?(?:(?P<minutes>\d+)[Mm])?(?:(?P<seconds>\d+)[Ss])?)?'
365367
)
366368

367369
# Fetch the match groups with default value of 0 (not None)
368370
m = regex.match(period)
369371
if not m:
370372
return None
371373

372-
duration = m.groupdict(0)
374+
# workaround error: Argument 1 to "groupdict" of "Match" has incompatible type "int"; expected "str"
375+
duration = m.groupdict(0) # type: ignore
373376

374377
# Create the timedelta object from extracted groups
375378
delta = timedelta(
@@ -456,25 +459,25 @@ def valid_until_ts(elt, default_ts: int) -> int:
456459
if valid_until is not None:
457460
try:
458461
dt = datetime.fromtimestamp(valid_until)
459-
except Exception:
460-
dt = None
461-
if dt is not None:
462462
ts = totimestamp(dt)
463+
except Exception:
464+
pass
463465

464466
cache_duration = elt.get("cacheDuration", None)
465467
if cache_duration is not None:
466-
dt = utc_now() + duration2timedelta(cache_duration)
467-
if dt is not None:
468+
_duration = duration2timedelta(cache_duration)
469+
if _duration is not None:
470+
dt = utc_now() + _duration
468471
ts = totimestamp(dt)
469472

470473
return ts
471474

472475

473-
def total_seconds(dt: Union[datetime, timedelta]) -> float:
476+
def total_seconds(dt: timedelta) -> float:
474477
if hasattr(dt, "total_seconds"):
475478
return dt.total_seconds()
476-
else:
477-
return (dt.microseconds + (dt.seconds + dt.days * 24 * 3600) * 10 ** 6) / 10 ** 6
479+
# TODO: Remove? I guess this is for Python < 3
480+
return (dt.microseconds + (dt.seconds + dt.days * 24 * 3600) * 10 ** 6) / 10 ** 6
478481

479482

480483
def etag(s):

0 commit comments

Comments
 (0)