Open u3Izx9ql7vW4 opened 1 week ago
Please add the traceback or if none, explain 'cannot be used'. What happens that you say this?
The arguments in a match pattern are compared to attributes of the object, that is:
match td:
case timedelta(hours=1):
print("hour")
is more or less equivalent to:
if isinstance(td, timedelta) and hasattr(td, "hours") and td.hours == 1:
print("hour")
Timedelta instances do not have a "hours" attributes. Changing this would be a backward incompatibility break, especially for the attributes days
and seconds
(timedelta(weeks=4).days == 28
).
Bug report
Bug description:
Timedelta cannot be evaluated in match statements, see example below
CPython versions tested on:
3.11
Operating systems tested on:
macOS