@@ -3141,35 +3141,60 @@ datetime_date_fromtimestamp_capi(PyObject *cls, PyObject *args)
3141
3141
return result ;
3142
3142
}
3143
3143
3144
- /* Return new date from proleptic Gregorian ordinal. Raises ValueError if
3145
- * the ordinal is out of range.
3146
- */
3144
+ /*[clinic input]
3145
+ @classmethod
3146
+ datetime.date.fromordinal
3147
+
3148
+ cls: self(type="PyObject *")
3149
+ defcls: defining_class
3150
+ ordinal: int
3151
+ /
3152
+
3153
+ int -> date corresponding to a proleptic Gregorian ordinal.
3154
+
3155
+ Return new date from proleptic Gregorian ordinal. Raises ValueError
3156
+ if the ordinal is out of range.
3157
+ [clinic start generated code]*/
3158
+
3147
3159
static PyObject *
3148
- date_fromordinal (PyObject * cls , PyObject * args )
3160
+ datetime_date_fromordinal_impl (PyObject * cls , PyTypeObject * defcls ,
3161
+ int ordinal )
3162
+ /*[clinic end generated code: output=fa7ca4621f1ee8be input=76c85e045fdfbc97]*/
3149
3163
{
3150
3164
PyObject * result = NULL ;
3151
- int ordinal ;
3152
-
3153
- if (PyArg_ParseTuple (args , "i:fromordinal" , & ordinal )) {
3154
- int year ;
3155
- int month ;
3156
- int day ;
3165
+ int year ;
3166
+ int month ;
3167
+ int day ;
3157
3168
3158
- if (ordinal < 1 )
3159
- PyErr_SetString (PyExc_ValueError , "ordinal must be "
3160
- ">= 1" );
3161
- else {
3162
- ord_to_ymd (ordinal , & year , & month , & day );
3163
- datetime_state * st = find_module_state_by_def (cls );
3164
- result = new_date_subclass_ex (st , year , month , day , cls );
3165
- }
3169
+ if (ordinal < 1 ) {
3170
+ PyErr_SetString (PyExc_ValueError , "ordinal must be >= 1" );
3171
+ }
3172
+ else {
3173
+ ord_to_ymd (ordinal , & year , & month , & day );
3174
+ datetime_state * st = get_module_state_by_cls (defcls );
3175
+ result = new_date_subclass_ex (st , year , month , day , cls );
3166
3176
}
3167
3177
return result ;
3168
3178
}
3169
3179
3170
- /* Return the new date from a string as generated by date.isoformat() */
3180
+ /*[clinic input]
3181
+ @classmethod
3182
+ datetime.date.fromisoformat
3183
+
3184
+ cls: self(type="PyObject *")
3185
+ defcls: defining_class
3186
+ dtstr: object
3187
+ /
3188
+
3189
+ str -> Construct a date from a string in ISO 8601 format.
3190
+
3191
+ Return the new date from a string as generated by date.isoformat().
3192
+ [clinic start generated code]*/
3193
+
3171
3194
static PyObject *
3172
- date_fromisoformat (PyObject * cls , PyObject * dtstr )
3195
+ datetime_date_fromisoformat_impl (PyObject * cls , PyTypeObject * defcls ,
3196
+ PyObject * dtstr )
3197
+ /*[clinic end generated code: output=c382fc14a39f8b89 input=67564908cc8f0013]*/
3173
3198
{
3174
3199
assert (dtstr != NULL );
3175
3200
@@ -3199,7 +3224,7 @@ date_fromisoformat(PyObject *cls, PyObject *dtstr)
3199
3224
if (rv < 0 ) {
3200
3225
goto invalid_string_error ;
3201
3226
}
3202
- datetime_state * st = find_module_state_by_def ( cls );
3227
+ datetime_state * st = get_module_state_by_cls ( defcls );
3203
3228
return new_date_subclass_ex (st , year , month , day , cls );
3204
3229
3205
3230
invalid_string_error :
@@ -3717,15 +3742,8 @@ static PyMethodDef date_methods[] = {
3717
3742
3718
3743
/* Class methods: */
3719
3744
DATETIME_DATE_FROMTIMESTAMP_METHODDEF
3720
-
3721
- {"fromordinal" , (PyCFunction )date_fromordinal , METH_VARARGS |
3722
- METH_CLASS ,
3723
- PyDoc_STR ("int -> date corresponding to a proleptic Gregorian "
3724
- "ordinal." )},
3725
-
3726
- {"fromisoformat" , (PyCFunction )date_fromisoformat , METH_O |
3727
- METH_CLASS ,
3728
- PyDoc_STR ("str -> Construct a date from a string in ISO 8601 format." )},
3745
+ DATETIME_DATE_FROMORDINAL_METHODDEF
3746
+ DATETIME_DATE_FROMISOFORMAT_METHODDEF
3729
3747
3730
3748
{"fromisocalendar" , _PyCFunction_CAST (date_fromisocalendar ),
3731
3749
METH_VARARGS | METH_KEYWORDS | METH_CLASS ,
0 commit comments