Description
found a comment in _strptime.py that I believe is unnecessary and potentially outdated:
Line 304 in 8c3fd1f
The comment reads:
# XXX: Does 'Y' need to worry about having less or more than 4 digits?
This question seems irrelevant based on the current documentation and implementation standards. Here are my reasons:
-
Python documentation specifies a 4-digit restriction
The Python documentation for datetime.strptime states: Thestrptime()
method can parse years in the full [1, 9999] range, but years < 1000 must be zero-filled to 4-digit width. This makes it clear that Y is explicitly designed for 4-digit years only. -
Supporting more than 4 digits is impractical
Years with 5 or more digits cannot be represented in the resulting datetime type. The datetime implementation enforces the [1, 9999] year range, which inherently limits support for larger year values. -
Support for fewer than 4 digits tends to not standard-compliant
Some popular specifications expect a minimum of 4 digits for representing a year:
- ISO 8601: Requires at least 4 digits for year representation.
- RFC 3339: Also requires at least 4 digits for the year.
- POSIX.1-2008: While the standard doesn’t explicitly mandate the number of digits for %Y, implementations commonly expect 4 digits as a minimum.
Given these points, I propose removing the comment as it no longer adds value and could potentially confuse contributors or maintainers. If desired, I can submit a pull request to address this.
Linked PRs
- gh-127552: Remove comment questioning 4-digit restriction for ‘Y’ in datetime.strptime patterns #127590
- [3.12] gh-127552: Remove comment questioning 4-digit restriction for ‘Y’ in datetime.strptime patterns (GH-127590) #127649
- [3.13] gh-127552: Remove comment questioning 4-digit restriction for ‘Y’ in datetime.strptime patterns (GH-127590) #127650
Metadata
Metadata
Assignees
Projects
Status
Status