Skip to content

Timedelta cannot be used in match statements #123882

@user529481

Description

@user529481

Bug report

Bug description:

Timedelta cannot be evaluated in match statements, see example below

from datetime import timedelta

td = timedelta(hours=1)

print(td == timedelta(hours=1)) # evaluates to True

match td:
    case timedelta(days=1):
        print('day')
    case timedelta(hours=1):
        print('hour')
    case _:
        print('unhandled') # prints `unhandled`

CPython versions tested on:

3.11

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions