`datetime.strptime` accepts incompatible arguments
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
If you over-specify a datetime strptime string, it seems that datetime.strptime when encountering a component that has been specified twice, will overwrite earlier values with more recent ones.
>>> datetime.strptime("200099", "%Y%y")
datetime.datetime(1999, 1, 1, 0, 0)
One approach would be to ban over-specified formats, but that would be a problem for someone who wants to, use a format like "%M %B" (e.g. something sortable by month number while also showing month name), so I think we don't want to do that.
Alternatively we could start raising an exception if you get different values from these two things, or possibly a warning.
Or we can just accept that if you use a weird format you should expect weird behavior.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-125009
- gh-132524
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 at the datetime.strptime implementation and inspect linked PRs gh-125009 and gh-132524 for the current direction and related tests. Resolve whether conflicting repeated fields should raise, warn, or remain accepted; done means the behavior and tests reflect a decided policy.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100