`datetime.strptime(dt.strftime("%c"), "%c"))` fails when year is <1000.
Đang mở
Chưa có ai nhận issue này.
stdlib
type-bug
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
Bug description:
>>> from datetime import datetime
>>> datetime.strptime(datetime(1000, 1, 1).strftime("%c"), "%c")
datetime.datetime(1000, 1, 1, 0, 0)
>>> datetime.strptime(datetime(999, 1, 1).strftime("%c"), "%c")
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
datetime.strptime(datetime(999, 1, 1).strftime("%c"), "%c")
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nlx5/Documents/Programming/Python/cpython/Lib/_strptime.py", line 573, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
File "/home/nlx5/Documents/Programming/Python/cpython/Lib/_strptime.py", line 352, in _strptime
raise ValueError("time data %r does not match format %r" %
(data_string, format))
ValueError: time data 'Tue Jan 1 00:00:00 999' does not match format '%c'
Discovered this when adding some hypothesis tests for strptime/strftime. I doubt this is a real problem anyone is going to have in the real world, but maybe.
I do not know if this is locale-specific or OS specific.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-124778
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với việc tái hiện datetime.strptime/strftime trong issue và kiểm tra Lib/_strptime.py, đặc biệt là đường dẫn parsing cho %c. Kiểm tra hành vi với các năm nhỏ hơn 1000 và trong môi trường Linux được báo cáo; hoàn tất khi round trip của năm 999 thành công mà không làm hỏng hành vi parsing hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100