from datetime import datetime 会检查。import 多次只检查一次:

1, 1, 1
9999, 12,31
0   _datetime.cpython-313-darwin.so     0x000000010376cfa8 check_date_args + 76
1   _datetime.cpython-313-darwin.so     0x000000010375f768 new_date_ex + 36
2   _datetime.cpython-313-darwin.so     0x000000010375ef68 PyInit__datetime + 564
3   python.exe                          0x00000001030167ec _PyImport_LoadDynamicModuleWithSpec + 556
4   python.exe                          0x00000001030160f4 _imp_create_dynamic + 464
5   python.exe                          0x0000000102f1c96c cfunction_vectorcall_FASTCALL + 272
6   python.exe                          0x0000000102fcf864 _PyEval_EvalFrameDefault + 10504
7   python.exe                          0x0000000102ecf60c object_vacall + 292
8   python.exe                          0x0000000102ecf444 PyObject_CallMethodObjArgs + 104
9   python.exe                          0x0000000103013db0 PyImport_ImportModuleLevelObject + 1884
1, 1, 1
9999, 12, 31
1970, 1, 1
0   _datetime.cpython-313-darwin.so     0x000000010376cfa8 check_date_args + 76
1   _datetime.cpython-313-darwin.so     0x000000010375f9b8 new_datetime_ex2 + 84
2   _datetime.cpython-313-darwin.so     0x000000010375f1b0 PyInit__datetime + 1148
3   python.exe                          0x00000001030167ec _PyImport_LoadDynamicModuleWithSpec + 556
4   python.exe                          0x00000001030160f4 _imp_create_dynamic + 464
5   python.exe                          0x0000000102f1c96c cfunction_vectorcall_FASTCALL + 272
6   python.exe                          0x0000000102fcf864 _PyEval_EvalFrameDefault + 10504
7   python.exe                          0x0000000102ecf60c object_vacall + 292
8   python.exe                          0x0000000102ecf444 PyObject_CallMethodObjArgs + 104
9   python.exe                          0x0000000103013db0 PyImport_ImportModuleLevelObject + 1884

 

 

第一次执行,time.strptime or datetime.strptime 会检查:

2001, 1, 1 - 2001, 12, 1
2001, 1, 1 - 2001, 1, 1,7
1970,1 , 1
0   _datetime.cpython-313-darwin.so     0x00000001053a8fa8 check_date_args + 76
1   _datetime.cpython-313-darwin.so     0x000000010539e348 date_new + 452
2   python.exe                          0x0000000104b88ec8 type_call + 92
3   python.exe                          0x0000000104b09a38 _PyObject_MakeTpCall + 308
4   python.exe                          0x0000000104c0ab94 _PyEval_EvalFrameDefault + 7224
5   python.exe                          0x0000000104c08cfc PyEval_EvalCode + 288
6   python.exe                          0x0000000104c05e38 builtin_exec + 1064
7   python.exe                          0x0000000104b58a34 cfunction_vectorcall_FASTCALL_KEYWORDS + 168
8   python.exe                          0x0000000104c0b864 _PyEval_EvalFrameDefault + 10504
9   python.exe                          0x0000000104b0b60c object_vacall + 292
0   _datetime.cpython-313-darwin.so     0x000000010290cfa8 check_date_args + 76
1   _datetime.cpython-313-darwin.so     0x0000000102902348 date_new + 452
2   python.exe                          0x00000001020ecec8 type_call + 92
3   python.exe                          0x000000010206da38 _PyObject_MakeTpCall + 308
4   python.exe                          0x000000010216eb94 _PyEval_EvalFrameDefault + 7224
5   python.exe                          0x00000001021689b0 builtin___build_class__ + 1212
6   python.exe                          0x00000001020bca34 cfunction_vectorcall_FASTCALL_KEYWORDS + 168
7   python.exe                          0x000000010206e134 PyObject_Vectorcall + 88
8   python.exe                          0x000000010216eb94 _PyEval_EvalFrameDefault + 7224
9   python.exe                          0x000000010216ccfc PyEval_EvalCode + 288

 

time.strptime("02-29", "%m-%d") 后续执行检查:

1904, 2, 29
1904, 1, 1
1904, 2, 29

检查堆栈:

0   _datetime.cpython-313-darwin.so     0x0000000104b4cfa8 check_date_args + 76
1   _datetime.cpython-313-darwin.so     0x0000000104b42348 date_new + 452
2   python.exe                          0x000000010432cec8 type_call + 92
3   python.exe                          0x00000001042ada38 _PyObject_MakeTpCall + 308
4   python.exe                          0x00000001043aeb94 _PyEval_EvalFrameDefault + 7224
5   python.exe                          0x00000001044896a8 time_strptime + 56
6   python.exe                          0x00000001042fd288 cfunction_call + 180
7   python.exe                          0x00000001042ada38 _PyObject_MakeTpCall + 308
8   python.exe                          0x00000001043aeb94 _PyEval_EvalFrameDefault + 7224
9   python.exe                          0x00000001043accfc PyEval_EvalCode + 288

 

datetime.strptime("02-29", "%m-%d") 会检查

1904, 2, 29
1904, 1, 1
1904, 2, 29
0   _datetime.cpython-313-darwin.so     0x0000000104b4cfa8 check_date_args + 76
1   _datetime.cpython-313-darwin.so     0x0000000104b42348 date_new + 452
2   python.exe                          0x000000010432cec8 type_call + 92
3   python.exe                          0x00000001042ada38 _PyObject_MakeTpCall + 308
4   python.exe                          0x00000001043aeb94 _PyEval_EvalFrameDefault + 7224
5   python.exe                          0x00000001042af60c object_vacall + 292
6   python.exe                          0x00000001042af444 PyObject_CallMethodObjArgs + 104
7   _datetime.cpython-313-darwin.so     0x0000000104b46e44 datetime_strptime + 124
8   python.exe                          0x00000001042fd288 cfunction_call + 180
9   python.exe                          0x00000001042ada38 _PyObject_MakeTpCall + 308

1900, 2, 29 - 检查堆栈:

0   _datetime.cpython-313-darwin.so     0x0000000104b4cfa8 check_date_args + 76
1   _datetime.cpython-313-darwin.so     0x0000000104b3f9b8 new_datetime_ex2 + 84
2   _datetime.cpython-313-darwin.so     0x0000000104b45c40 datetime_new + 552
3   python.exe                          0x000000010432cec8 type_call + 92
4   python.exe                          0x00000001042ae29c _PyObject_Call + 184
5   python.exe                          0x00000001043af864 _PyEval_EvalFrameDefault + 10504
6   python.exe                          0x00000001042af60c object_vacall + 292
7   python.exe                          0x00000001042af444 PyObject_CallMethodObjArgs + 104
8   _datetime.cpython-313-darwin.so     0x0000000104b46e44 datetime_strptime + 124
9   python.exe                          0x00000001042fd288 cfunction_call + 180