[英]Origin of exception message in datetime module. ValueError: year 10000 is out of range
Using Python 3.8:使用 Python 3.8:
In [12]: datetime(10000, month=2, day=1)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-12-f4737756e718> in <module>
----> 1 datetime(10000, month=2, day=1)
ValueError: year 10000 is out of range
Note that I'm aware that datetime.datetime doesn't support years with five digits, so I'm not asking why 10000 doesn't work.请注意,我知道 datetime.datetime 不支持五位数的年份,所以我不是问为什么 10000 不起作用。
I was wondering where the message of the ValueError exception comes from as I don't see anything like year {year} is out of range
in the lib/datetime.py code.我想知道 ValueError 异常的消息来自哪里,因为我在lib/datetime.py代码中没有看到
year {year} is out of range
。
The only similarity is in theline 894 but is not the same message.唯一的相似之处在于第894 行,但不是同一条消息。
The actual implementation of datetime.datetime
is in _datetimemodule.c
and not in datetime.py
. datetime.datetime
的实际实现在_datetimemodule.c
而不是datetime.py
。
In the C implementation, you can see, as @wjandrea mentioned PyErr_Format(PyExc_ValueError, "year %i is out of range", year);
在 C 实现中,您可以看到,正如@wjandrea 提到的
PyErr_Format(PyExc_ValueError, "year %i is out of range", year);
in function check_date_args
in line 420 .在第 420 行的函数
check_date_args
中。 That one ends up being called from datetime_new
, which is used to construct datetime.datetime
, see line 6334 .即一端向上被调用
datetime_new
,其被用于构建datetime.datetime
,见线6334 。
And about the question how it goes from datetime.py
to the c implementation, there is this line :关于它如何从
datetime.py
到 c 实现的问题,有这一行:
from _datetime import *
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.