Timedelta cannot be used in match statements
Open
Nobody has claimed this yet.
extension-modules
stdlib
type-feature
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided timedelta match statement on CPython 3.11 and compare its behavior with equality. The issue names no source file or test entry point, so trace how class patterns handle timedelta attributes and determine the expected matching behavior before identifying an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100