diff --git a/Modules/_cryptmodule.c b/Modules/_cryptmodule.c --- a/Modules/_cryptmodule.c +++ b/Modules/_cryptmodule.c @@ -45,13 +45,13 @@ crypt_crypt_impl(PyModuleDef *module, const char *word, const char *salt); static PyObject * -crypt_crypt(PyModuleDef *module, PyObject *args) +crypt_crypt(PyModuleDef *module, PyObject *_args) { PyObject *return_value = NULL; const char *word; const char *salt; - if (!PyArg_ParseTuple(args, + if (!PyArg_ParseTuple(_args, "ss:crypt", &word, &salt)) goto exit; @@ -63,7 +63,7 @@ static PyObject * crypt_crypt_impl(PyModuleDef *module, const char *word, const char *salt) -/*[clinic end generated code: checksum=a137540bf6862f9935fc112b8bb1d62d6dd1ad02]*/ +/*[clinic end generated code: checksum=062113191fa0f0be2385793b22433cd1967cb378]*/ { /* On some platforms (AtheOS) crypt returns NULL for an invalid salt. Return None in that case. XXX Maybe raise an exception? */ diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -608,7 +608,7 @@ curses_window_addch_impl(PyObject *self, int group_left_1, int x, int y, PyObject *ch, int group_right_1, long attr); static PyObject * -curses_window_addch(PyObject *self, PyObject *args) +curses_window_addch(PyObject *self, PyObject *_args) { PyObject *return_value = NULL; int group_left_1 = 0; @@ -618,23 +618,23 @@ int group_right_1 = 0; long attr = 0; - switch (PyTuple_GET_SIZE(args)) { + switch (PyTuple_GET_SIZE(_args)) { case 1: - if (!PyArg_ParseTuple(args, "O:addch", &ch)) + if (!PyArg_ParseTuple(_args, "O:addch", &ch)) return NULL; break; case 2: - if (!PyArg_ParseTuple(args, "Ol:addch", &ch, &attr)) + if (!PyArg_ParseTuple(_args, "Ol:addch", &ch, &attr)) return NULL; group_right_1 = 1; break; case 3: - if (!PyArg_ParseTuple(args, "iiO:addch", &x, &y, &ch)) + if (!PyArg_ParseTuple(_args, "iiO:addch", &x, &y, &ch)) return NULL; group_left_1 = 1; break; case 4: - if (!PyArg_ParseTuple(args, "iiOl:addch", &x, &y, &ch, &attr)) + if (!PyArg_ParseTuple(_args, "iiOl:addch", &x, &y, &ch, &attr)) return NULL; group_right_1 = 1; group_left_1 = 1; @@ -650,7 +650,7 @@ static PyObject * curses_window_addch_impl(PyObject *self, int group_left_1, int x, int y, PyObject *ch, int group_right_1, long attr) -/*[clinic end generated code: checksum=b073327add8197b6ba7fb96c87062422c8312954]*/ +/*[clinic end generated code: checksum=0947eadd7294b1d05053f8363eb9ee74b5effb23]*/ { PyCursesWindowObject *cwself = (PyCursesWindowObject *)self; int coordinates_group = group_left_1; diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -4174,13 +4174,13 @@ datetime_datetime_now_impl(PyTypeObject *cls, PyObject *tz); static PyObject * -datetime_datetime_now(PyTypeObject *cls, PyObject *args, PyObject *kwargs) +datetime_datetime_now(PyTypeObject *cls, PyObject *_args, PyObject *_kwargs) { PyObject *return_value = NULL; static char *_keywords[] = {"tz", NULL}; PyObject *tz = Py_None; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, + if (!PyArg_ParseTupleAndKeywords(_args, _kwargs, "|O:now", _keywords, &tz)) goto exit; @@ -4192,7 +4192,7 @@ static PyObject * datetime_datetime_now_impl(PyTypeObject *cls, PyObject *tz) -/*[clinic end generated code: checksum=ca3d26a423b3f633b260c7622e303f0915a96f7c]*/ +/*[clinic end generated code: checksum=336278c1b866178128c2cb0e9a3de287b0285945]*/ { PyObject *self; diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c --- a/Modules/_dbmmodule.c +++ b/Modules/_dbmmodule.c @@ -289,7 +289,7 @@ dbm_dbm_get_impl(dbmobject *dp, const char *key, Py_ssize_clean_t key_length, int group_right_1, PyObject *default_value); static PyObject * -dbm_dbm_get(PyObject *self, PyObject *args) +dbm_dbm_get(PyObject *self, PyObject *_args) { PyObject *return_value = NULL; const char *key; @@ -297,13 +297,13 @@ int group_right_1 = 0; PyObject *default_value = NULL; - switch (PyTuple_GET_SIZE(args)) { + switch (PyTuple_GET_SIZE(_args)) { case 1: - if (!PyArg_ParseTuple(args, "s#:get", &key, &key_length)) + if (!PyArg_ParseTuple(_args, "s#:get", &key, &key_length)) return NULL; break; case 2: - if (!PyArg_ParseTuple(args, "s#O:get", &key, &key_length, &default_value)) + if (!PyArg_ParseTuple(_args, "s#O:get", &key, &key_length, &default_value)) return NULL; group_right_1 = 1; break; @@ -318,7 +318,7 @@ static PyObject * dbm_dbm_get_impl(dbmobject *dp, const char *key, Py_ssize_clean_t key_length, int group_right_1, PyObject *default_value) -/*[clinic end generated code: checksum=2c3209571267017f1b9abbd19e1b521849fd5d4a]*/ +/*[clinic end generated code: checksum=e82b4c4c4bd5087d67d6787faedca13215d2e99f]*/ { datum dbm_key, val; @@ -479,14 +479,14 @@ dbmopen_impl(PyModuleDef *module, const char *filename, const char *flags, int mode); static PyObject * -dbmopen(PyModuleDef *module, PyObject *args) +dbmopen(PyModuleDef *module, PyObject *_args) { PyObject *return_value = NULL; const char *filename; const char *flags = "r"; int mode = 438; - if (!PyArg_ParseTuple(args, + if (!PyArg_ParseTuple(_args, "s|si:open", &filename, &flags, &mode)) goto exit; @@ -498,7 +498,7 @@ static PyObject * dbmopen_impl(PyModuleDef *module, const char *filename, const char *flags, int mode) -/*[clinic end generated code: checksum=fb265f75641553ccd963f84c143b35c11f9121fc]*/ +/*[clinic end generated code: checksum=e1cd323b12823a12004cced13705e996d3253125]*/ { int iflags; diff --git a/Modules/_opcode.c b/Modules/_opcode.c --- a/Modules/_opcode.c +++ b/Modules/_opcode.c @@ -31,7 +31,7 @@ _opcode_stack_effect_impl(PyModuleDef *module, int opcode, int group_right_1, int oparg); static PyObject * -_opcode_stack_effect(PyModuleDef *module, PyObject *args) +_opcode_stack_effect(PyModuleDef *module, PyObject *_args) { PyObject *return_value = NULL; int opcode; @@ -39,13 +39,13 @@ int oparg = 0; int _return_value; - switch (PyTuple_GET_SIZE(args)) { + switch (PyTuple_GET_SIZE(_args)) { case 1: - if (!PyArg_ParseTuple(args, "i:stack_effect", &opcode)) + if (!PyArg_ParseTuple(_args, "i:stack_effect", &opcode)) return NULL; break; case 2: - if (!PyArg_ParseTuple(args, "ii:stack_effect", &opcode, &oparg)) + if (!PyArg_ParseTuple(_args, "ii:stack_effect", &opcode, &oparg)) return NULL; group_right_1 = 1; break; @@ -64,7 +64,7 @@ static int _opcode_stack_effect_impl(PyModuleDef *module, int opcode, int group_right_1, int oparg) -/*[clinic end generated code: checksum=47e76ec27523da4ab192713642d32482cd743aa4]*/ +/*[clinic end generated code: checksum=923a264d04415706529abb30dba88b2372a886f3]*/ { int effect; if (HAS_ARG(opcode)) { diff --git a/Modules/_pickle.c b/Modules/_pickle.c --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -3906,16 +3906,12 @@ static PyObject * _pickle_Pickler_clear_memo(PyObject *self, PyObject *Py_UNUSED(ignored)) { - PyObject *return_value = NULL; - - return_value = _pickle_Pickler_clear_memo_impl((PicklerObject *)self); - - return return_value; + return _pickle_Pickler_clear_memo_impl((PicklerObject *)self); } static PyObject * _pickle_Pickler_clear_memo_impl(PicklerObject *self) -/*[clinic end generated code: checksum=0574593b102fffb8e781d7bb9b536ceffc525ac1]*/ +/*[clinic end generated code: checksum=015cc3c5befea86cb08b9396938477bebbea4157]*/ { if (self->memo) PyMemoTable_Clear(self->memo); @@ -4072,7 +4068,7 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, PyObject *protocol, int fix_imports); static PyObject * -_pickle_Pickler___init__(PyObject *self, PyObject *args, PyObject *kwargs) +_pickle_Pickler___init__(PyObject *self, PyObject *_args, PyObject *_kwargs) { PyObject *return_value = NULL; static char *_keywords[] = {"file", "protocol", "fix_imports", NULL}; @@ -4080,7 +4076,7 @@ PyObject *protocol = NULL; int fix_imports = 1; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, + if (!PyArg_ParseTupleAndKeywords(_args, _kwargs, "O|Op:__init__", _keywords, &file, &protocol, &fix_imports)) goto exit; @@ -4092,7 +4088,7 @@ static PyObject * _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, PyObject *protocol, int fix_imports) -/*[clinic end generated code: checksum=defa3d9e9f8b51fb257d4fdfca99db503db0e6df]*/ +/*[clinic end generated code: checksum=298834a68c5bba41bf6569cb417f893947af8fa1]*/ { _Py_IDENTIFIER(persistent_id); _Py_IDENTIFIER(dispatch_table); @@ -4191,16 +4187,12 @@ static PyObject * _pickle_PicklerMemoProxy_clear(PyObject *self, PyObject *Py_UNUSED(ignored)) { - PyObject *return_value = NULL; - - return_value = _pickle_PicklerMemoProxy_clear_impl((PicklerMemoProxyObject *)self); - - return return_value; + return _pickle_PicklerMemoProxy_clear_impl((PicklerMemoProxyObject *)self); } static PyObject * _pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self) -/*[clinic end generated code: checksum=c6ca252530ccb3ea2f4b33507b51b183f23b24c7]*/ +/*[clinic end generated code: checksum=bf8dd8c8688d0c0f7a2e59a804c47375b740f2f0]*/ { if (self->pickler->memo) PyMemoTable_Clear(self->pickler->memo); @@ -4228,16 +4220,12 @@ static PyObject * _pickle_PicklerMemoProxy_copy(PyObject *self, PyObject *Py_UNUSED(ignored)) { - PyObject *return_value = NULL; - - return_value = _pickle_PicklerMemoProxy_copy_impl((PicklerMemoProxyObject *)self); - - return return_value; + return _pickle_PicklerMemoProxy_copy_impl((PicklerMemoProxyObject *)self); } static PyObject * _pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self) -/*[clinic end generated code: checksum=808c4d5a37359ed5fb2efe81dbe5ff480719f470]*/ +/*[clinic end generated code: checksum=72d46879dc658adbd3d28b5c82dd8dcfa6b9b124]*/ { Py_ssize_t i; PyMemoTable *memo; @@ -4295,16 +4283,12 @@ static PyObject * _pickle_PicklerMemoProxy___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored)) { - PyObject *return_value = NULL; - - return_value = _pickle_PicklerMemoProxy___reduce___impl((PicklerMemoProxyObject *)self); - - return return_value; + return _pickle_PicklerMemoProxy___reduce___impl((PicklerMemoProxyObject *)self); } static PyObject * _pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self) -/*[clinic end generated code: checksum=2293152bdf53951a012d430767b608f5fb4213b5]*/ +/*[clinic end generated code: checksum=aad71c4d81d1ed8bf0d32362dd80a29b9f3b0d03]*/ { PyObject *reduce_value, *dict_args; PyObject *contents = _pickle_PicklerMemoProxy_copy_impl(self); @@ -6342,16 +6326,12 @@ static PyObject * _pickle_Unpickler_load(PyObject *self, PyObject *Py_UNUSED(ignored)) { - PyObject *return_value = NULL; - - return_value = _pickle_Unpickler_load_impl(self); - - return return_value; + return _pickle_Unpickler_load_impl(self); } static PyObject * _pickle_Unpickler_load_impl(PyObject *self) -/*[clinic end generated code: checksum=55f35fcaf034817e75c355ec50b7878577355899]*/ +/*[clinic end generated code: checksum=9477099fe6a90748c13ff1a6dd92ba7ab7a89602]*/ { UnpicklerObject *unpickler = (UnpicklerObject*)self; @@ -6411,14 +6391,14 @@ _pickle_Unpickler_find_class_impl(UnpicklerObject *self, PyObject *module_name, PyObject *global_name); static PyObject * -_pickle_Unpickler_find_class(PyObject *self, PyObject *args) +_pickle_Unpickler_find_class(PyObject *self, PyObject *_args) { PyObject *return_value = NULL; PyObject *module_name; PyObject *global_name; - if (!PyArg_ParseTuple(args, - "OO:find_class", + if (!PyArg_UnpackTuple(_args, "find_class", + 2, 2, &module_name, &global_name)) goto exit; return_value = _pickle_Unpickler_find_class_impl((UnpicklerObject *)self, module_name, global_name); @@ -6429,7 +6409,7 @@ static PyObject * _pickle_Unpickler_find_class_impl(UnpicklerObject *self, PyObject *module_name, PyObject *global_name) -/*[clinic end generated code: checksum=1f353d13a32c9d94feb1466b3c2d0529a7e5650e]*/ +/*[clinic end generated code: checksum=7e3e57778127895395c02daeccea757bb1484253]*/ { PyObject *global; PyObject *modules_dict; @@ -6638,7 +6618,7 @@ _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, int fix_imports, const char *encoding, const char *errors); static PyObject * -_pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs) +_pickle_Unpickler___init__(PyObject *self, PyObject *_args, PyObject *_kwargs) { PyObject *return_value = NULL; static char *_keywords[] = {"file", "fix_imports", "encoding", "errors", NULL}; @@ -6647,7 +6627,7 @@ const char *encoding = "ASCII"; const char *errors = "strict"; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, + if (!PyArg_ParseTupleAndKeywords(_args, _kwargs, "O|$pss:__init__", _keywords, &file, &fix_imports, &encoding, &errors)) goto exit; @@ -6659,7 +6639,7 @@ static PyObject * _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, int fix_imports, const char *encoding, const char *errors) -/*[clinic end generated code: checksum=26c1d4a06841a8e51d29a0c244ba7f4607ff358a]*/ +/*[clinic end generated code: checksum=2e6e89bb3159b4af39a527ed3ade7f8ab507599b]*/ { _Py_IDENTIFIER(persistent_load); @@ -6752,16 +6732,12 @@ static PyObject * _pickle_UnpicklerMemoProxy_clear(PyObject *self, PyObject *Py_UNUSED(ignored)) { - PyObject *return_value = NULL; - - return_value = _pickle_UnpicklerMemoProxy_clear_impl((UnpicklerMemoProxyObject *)self); - - return return_value; + return _pickle_UnpicklerMemoProxy_clear_impl((UnpicklerMemoProxyObject *)self); } static PyObject * _pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self) -/*[clinic end generated code: checksum=e0f99c26d48444a3f58f598bec3190c66595fce7]*/ +/*[clinic end generated code: checksum=07adecee2181e5e268b2ff184360b1d88ad947f2]*/ { _Unpickler_MemoCleanup(self->unpickler); self->unpickler->memo = _Unpickler_NewMemo(self->unpickler->memo_size); @@ -6791,16 +6767,12 @@ static PyObject * _pickle_UnpicklerMemoProxy_copy(PyObject *self, PyObject *Py_UNUSED(ignored)) { - PyObject *return_value = NULL; - - return_value = _pickle_UnpicklerMemoProxy_copy_impl((UnpicklerMemoProxyObject *)self); - - return return_value; + return _pickle_UnpicklerMemoProxy_copy_impl((UnpicklerMemoProxyObject *)self); } static PyObject * _pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self) -/*[clinic end generated code: checksum=8c0ab91c0b694ea71a1774650898a760d1ab4765]*/ +/*[clinic end generated code: checksum=47b9f0cc12c5a54004252e1b4916822cdfa8a881]*/ { Py_ssize_t i; PyObject *new_memo = PyDict_New(); @@ -6851,16 +6823,12 @@ static PyObject * _pickle_UnpicklerMemoProxy___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored)) { - PyObject *return_value = NULL; - - return_value = _pickle_UnpicklerMemoProxy___reduce___impl((UnpicklerMemoProxyObject *)self); - - return return_value; + return _pickle_UnpicklerMemoProxy___reduce___impl((UnpicklerMemoProxyObject *)self); } static PyObject * _pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self) -/*[clinic end generated code: checksum=4ee76a65511291f0de2e9e63db395d2e5d6d8df6]*/ +/*[clinic end generated code: checksum=2f061bb9ecd9ee8500184c135148a131c46a3b88]*/ { PyObject *reduce_value; PyObject *constructor_args; @@ -7199,7 +7167,7 @@ _pickle_dump_impl(PyModuleDef *module, PyObject *obj, PyObject *file, PyObject *protocol, int fix_imports); static PyObject * -_pickle_dump(PyModuleDef *module, PyObject *args, PyObject *kwargs) +_pickle_dump(PyModuleDef *module, PyObject *_args, PyObject *_kwargs) { PyObject *return_value = NULL; static char *_keywords[] = {"obj", "file", "protocol", "fix_imports", NULL}; @@ -7208,7 +7176,7 @@ PyObject *protocol = NULL; int fix_imports = 1; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, + if (!PyArg_ParseTupleAndKeywords(_args, _kwargs, "OO|O$p:dump", _keywords, &obj, &file, &protocol, &fix_imports)) goto exit; @@ -7220,7 +7188,7 @@ static PyObject * _pickle_dump_impl(PyModuleDef *module, PyObject *obj, PyObject *file, PyObject *protocol, int fix_imports) -/*[clinic end generated code: checksum=eb5c23e64da34477178230b704d2cc9c6b6650ea]*/ +/*[clinic end generated code: checksum=0efdd78beff31aaf209b19626df79bf34212243d]*/ { PicklerObject *pickler = _Pickler_New(); @@ -7294,7 +7262,7 @@ _pickle_dumps_impl(PyModuleDef *module, PyObject *obj, PyObject *protocol, int fix_imports); static PyObject * -_pickle_dumps(PyModuleDef *module, PyObject *args, PyObject *kwargs) +_pickle_dumps(PyModuleDef *module, PyObject *_args, PyObject *_kwargs) { PyObject *return_value = NULL; static char *_keywords[] = {"obj", "protocol", "fix_imports", NULL}; @@ -7302,7 +7270,7 @@ PyObject *protocol = NULL; int fix_imports = 1; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, + if (!PyArg_ParseTupleAndKeywords(_args, _kwargs, "O|O$p:dumps", _keywords, &obj, &protocol, &fix_imports)) goto exit; @@ -7314,7 +7282,7 @@ static PyObject * _pickle_dumps_impl(PyModuleDef *module, PyObject *obj, PyObject *protocol, int fix_imports) -/*[clinic end generated code: checksum=e9b915d61202a9692cb6c6718db74fe54fc9c4d1]*/ +/*[clinic end generated code: checksum=60b2006a81e41d1c1f09b5453df32070d0896371]*/ { PyObject *result; PicklerObject *pickler = _Pickler_New(); @@ -7405,7 +7373,7 @@ _pickle_load_impl(PyModuleDef *module, PyObject *file, int fix_imports, const char *encoding, const char *errors); static PyObject * -_pickle_load(PyModuleDef *module, PyObject *args, PyObject *kwargs) +_pickle_load(PyModuleDef *module, PyObject *_args, PyObject *_kwargs) { PyObject *return_value = NULL; static char *_keywords[] = {"file", "fix_imports", "encoding", "errors", NULL}; @@ -7414,7 +7382,7 @@ const char *encoding = "ASCII"; const char *errors = "strict"; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, + if (!PyArg_ParseTupleAndKeywords(_args, _kwargs, "O|$pss:load", _keywords, &file, &fix_imports, &encoding, &errors)) goto exit; @@ -7426,7 +7394,7 @@ static PyObject * _pickle_load_impl(PyModuleDef *module, PyObject *file, int fix_imports, const char *encoding, const char *errors) -/*[clinic end generated code: checksum=b41f06970e57acf2fd602e4b7f88e3f3e1e53087]*/ +/*[clinic end generated code: checksum=9b6bd34f9070bcbeed4e63a84ac75787079af873]*/ { PyObject *result; UnpicklerObject *unpickler = _Unpickler_New(); @@ -7501,7 +7469,7 @@ _pickle_loads_impl(PyModuleDef *module, PyObject *data, int fix_imports, const char *encoding, const char *errors); static PyObject * -_pickle_loads(PyModuleDef *module, PyObject *args, PyObject *kwargs) +_pickle_loads(PyModuleDef *module, PyObject *_args, PyObject *_kwargs) { PyObject *return_value = NULL; static char *_keywords[] = {"data", "fix_imports", "encoding", "errors", NULL}; @@ -7510,7 +7478,7 @@ const char *encoding = "ASCII"; const char *errors = "strict"; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, + if (!PyArg_ParseTupleAndKeywords(_args, _kwargs, "O|$pss:loads", _keywords, &data, &fix_imports, &encoding, &errors)) goto exit; @@ -7522,7 +7490,7 @@ static PyObject * _pickle_loads_impl(PyModuleDef *module, PyObject *data, int fix_imports, const char *encoding, const char *errors) -/*[clinic end generated code: checksum=0663de43aca6c21508a777e29d98c9c3a6e7f72d]*/ +/*[clinic end generated code: checksum=dbe19a0435df0a9b64f02cf6d4f0235395322f8d]*/ { PyObject *result; UnpicklerObject *unpickler = _Unpickler_New(); diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -551,7 +551,7 @@ pattern_match_impl(PatternObject *self, PyObject *pattern, Py_ssize_t pos, Py_ssize_t endpos); static PyObject * -pattern_match(PyObject *self, PyObject *args, PyObject *kwargs) +pattern_match(PyObject *self, PyObject *_args, PyObject *_kwargs) { PyObject *return_value = NULL; static char *_keywords[] = {"pattern", "pos", "endpos", NULL}; @@ -559,7 +559,7 @@ Py_ssize_t pos = 0; Py_ssize_t endpos = PY_SSIZE_T_MAX; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, + if (!PyArg_ParseTupleAndKeywords(_args, _kwargs, "O|nn:match", _keywords, &pattern, &pos, &endpos)) goto exit; @@ -571,7 +571,7 @@ static PyObject * pattern_match_impl(PatternObject *self, PyObject *pattern, Py_ssize_t pos, Py_ssize_t endpos) -/*[clinic end generated code: checksum=63e59c5f3019efe6c1f3acdec42b2d3595e14a09]*/ +/*[clinic end generated code: checksum=0df127a6fdb5b992b6a36d27138dfa5740621c5b]*/ { SRE_STATE state; Py_ssize_t status; diff --git a/Modules/_weakref.c b/Modules/_weakref.c --- a/Modules/_weakref.c +++ b/Modules/_weakref.c @@ -34,6 +34,7 @@ { PyObject *return_value = NULL; Py_ssize_t _return_value; + _return_value = _weakref_getweakrefcount_impl(module, object); if ((_return_value == -1) && PyErr_Occurred()) goto exit; @@ -45,7 +46,7 @@ static Py_ssize_t _weakref_getweakrefcount_impl(PyModuleDef *module, PyObject *object) -/*[clinic end generated code: checksum=436e8fbe0297434375f039d8c2d9fc3a9bbe773c]*/ +/*[clinic end generated code: checksum=744fa73ba68c0ee89567e9cb9bea11863270d516]*/ { PyWeakReference **list; diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -2458,7 +2458,7 @@ os_stat_impl(PyModuleDef *module, path_t *path, int dir_fd, int follow_symlinks); static PyObject * -os_stat(PyModuleDef *module, PyObject *args, PyObject *kwargs) +os_stat(PyModuleDef *module, PyObject *_args, PyObject *_kwargs) { PyObject *return_value = NULL; static char *_keywords[] = {"path", "dir_fd", "follow_symlinks", NULL}; @@ -2466,7 +2466,7 @@ int dir_fd = DEFAULT_DIR_FD; int follow_symlinks = 1; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, + if (!PyArg_ParseTupleAndKeywords(_args, _kwargs, "O&|$O&p:stat", _keywords, path_converter, &path, OS_STAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) goto exit; @@ -2481,7 +2481,7 @@ static PyObject * os_stat_impl(PyModuleDef *module, path_t *path, int dir_fd, int follow_symlinks) -/*[clinic end generated code: checksum=85a71ad602e89f8e280118da976f70cd2f9abdf1]*/ +/*[clinic end generated code: checksum=e314f8cc9f8abc101cfabde97e00d0c6e5d8cd6f]*/ { return posix_do_stat("stat", path, dir_fd, follow_symlinks); } @@ -2597,7 +2597,7 @@ os_access_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd, int effective_ids, int follow_symlinks); static PyObject * -os_access(PyModuleDef *module, PyObject *args, PyObject *kwargs) +os_access(PyModuleDef *module, PyObject *_args, PyObject *_kwargs) { PyObject *return_value = NULL; static char *_keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL}; @@ -2607,7 +2607,7 @@ int effective_ids = 0; int follow_symlinks = 1; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, + if (!PyArg_ParseTupleAndKeywords(_args, _kwargs, "O&i|$O&pp:access", _keywords, path_converter, &path, &mode, OS_STAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) goto exit; @@ -2622,7 +2622,7 @@ static PyObject * os_access_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd, int effective_ids, int follow_symlinks) -/*[clinic end generated code: checksum=636e835c36562a2fc11acab75314634127fdf769]*/ +/*[clinic end generated code: checksum=96c1d57d156c3978fe5832ca187fb3572035a710]*/ { PyObject *return_value = NULL; @@ -2731,13 +2731,13 @@ os_ttyname_impl(PyModuleDef *module, int fd); static PyObject * -os_ttyname(PyModuleDef *module, PyObject *args) +os_ttyname(PyModuleDef *module, PyObject *_args) { PyObject *return_value = NULL; int fd; char *_return_value; - if (!PyArg_ParseTuple(args, + if (!PyArg_ParseTuple(_args, "i:ttyname", &fd)) goto exit; @@ -2752,7 +2752,7 @@ static char * os_ttyname_impl(PyModuleDef *module, int fd) -/*[clinic end generated code: checksum=0f368134dc0a7f21f25185e2e6bacf7675fb473a]*/ +/*[clinic end generated code: checksum=e45cd667d5f51d6648d8a0916d382c4341b0f1ee]*/ { char *ret; diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -143,13 +143,13 @@ unicodedata_UCD_decimal_impl(PyObject *self, PyUnicodeObject *unichr, PyObject *default_value); static PyObject * -unicodedata_UCD_decimal(PyObject *self, PyObject *args) +unicodedata_UCD_decimal(PyObject *self, PyObject *_args) { PyObject *return_value = NULL; PyUnicodeObject *unichr; PyObject *default_value = NULL; - if (!PyArg_ParseTuple(args, + if (!PyArg_ParseTuple(_args, "O!|O:decimal", &PyUnicode_Type, &unichr, &default_value)) goto exit; @@ -161,7 +161,7 @@ static PyObject * unicodedata_UCD_decimal_impl(PyObject *self, PyUnicodeObject *unichr, PyObject *default_value) -/*[clinic end generated code: checksum=73edde0e9cd5913ea174c4fa81504369761b7426]*/ +/*[clinic end generated code: checksum=4528e9e4cc6585c51daf998d1714fddbd34f645a]*/ { PyUnicodeObject *v = (PyUnicodeObject *)unichr; int have_old = 0; diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -195,20 +195,20 @@ zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int group_right_1, int level); static PyObject * -zlib_compress(PyModuleDef *module, PyObject *args) +zlib_compress(PyModuleDef *module, PyObject *_args) { PyObject *return_value = NULL; Py_buffer bytes = {NULL, NULL}; int group_right_1 = 0; int level = 0; - switch (PyTuple_GET_SIZE(args)) { + switch (PyTuple_GET_SIZE(_args)) { case 1: - if (!PyArg_ParseTuple(args, "y*:compress", &bytes)) + if (!PyArg_ParseTuple(_args, "y*:compress", &bytes)) return NULL; break; case 2: - if (!PyArg_ParseTuple(args, "y*i:compress", &bytes, &level)) + if (!PyArg_ParseTuple(_args, "y*i:compress", &bytes, &level)) return NULL; group_right_1 = 1; break; @@ -227,7 +227,7 @@ static PyObject * zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int group_right_1, int level) -/*[clinic end generated code: checksum=66c4d16d0b8b9dd423648d9ef00d6a89d3363665]*/ +/*[clinic end generated code: checksum=e04ff3a49aa955025e0c90ec18f47ff467774b1c]*/ { PyObject *ReturnVal = NULL; Byte *input, *output = NULL; @@ -786,13 +786,13 @@ zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data, unsigned int max_length); static PyObject * -zlib_Decompress_decompress(PyObject *self, PyObject *args) +zlib_Decompress_decompress(PyObject *self, PyObject *_args) { PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; unsigned int max_length = 0; - if (!PyArg_ParseTuple(args, + if (!PyArg_ParseTuple(_args, "y*|O&:decompress", &data, uint_converter, &max_length)) goto exit; @@ -808,7 +808,7 @@ static PyObject * zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data, unsigned int max_length) -/*[clinic end generated code: checksum=e0058024c4a97b411d2e2197791b89fde175f76f]*/ +/*[clinic end generated code: checksum=3a4ea324024092f5b614beefd403d37425a8fdfa]*/ { int err; unsigned int old_length, length = DEFAULTALLOC; @@ -1047,16 +1047,12 @@ static PyObject * zlib_Compress_copy(PyObject *self, PyObject *Py_UNUSED(ignored)) { - PyObject *return_value = NULL; - - return_value = zlib_Compress_copy_impl((compobject *)self); - - return return_value; + return zlib_Compress_copy_impl((compobject *)self); } static PyObject * zlib_Compress_copy_impl(compobject *self) -/*[clinic end generated code: checksum=2f454ee15be3bc53cfb4e845c3f891f68be4c8e4]*/ +/*[clinic end generated code: checksum=d57a7911deb7940e85a8d7e65af20b6e2df69000]*/ { compobject *retval = NULL; int err; diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -12903,14 +12903,14 @@ unicode_maketrans_impl(void *null, PyObject *x, PyObject *y, PyObject *z); static PyObject * -unicode_maketrans(void *null, PyObject *args) +unicode_maketrans(void *null, PyObject *_args) { PyObject *return_value = NULL; PyObject *x; PyObject *y = NULL; PyObject *z = NULL; - if (!PyArg_ParseTuple(args, + if (!PyArg_ParseTuple(_args, "O|UU:maketrans", &x, &y, &z)) goto exit; @@ -12922,7 +12922,7 @@ static PyObject * unicode_maketrans_impl(void *null, PyObject *x, PyObject *y, PyObject *z) -/*[clinic end generated code: checksum=7f76f414a0dfd0c614e0d4717872eeb520516da7]*/ +/*[clinic end generated code: checksum=289a22df610ea6d871d9f6efd16ee542913d858e]*/ { PyObject *new = NULL, *key, *value; Py_ssize_t i = 0; diff --git a/Python/import.c b/Python/import.c --- a/Python/import.c +++ b/Python/import.c @@ -246,16 +246,12 @@ static PyObject * _imp_lock_held(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) { - PyObject *return_value = NULL; - - return_value = _imp_lock_held_impl(module); - - return return_value; + return _imp_lock_held_impl(module); } static PyObject * _imp_lock_held_impl(PyModuleDef *module) -/*[clinic end generated code: checksum=c5858b257881f94dee95526229a8d1a57ccff158]*/ +/*[clinic end generated code: checksum=ede1cafb78eb22e3009602f684c8b780e2b82d62]*/ { #ifdef WITH_THREAD return PyBool_FromLong(import_lock_thread != -1); @@ -289,16 +285,12 @@ static PyObject * _imp_acquire_lock(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) { - PyObject *return_value = NULL; - - return_value = _imp_acquire_lock_impl(module); - - return return_value; + return _imp_acquire_lock_impl(module); } static PyObject * _imp_acquire_lock_impl(PyModuleDef *module) -/*[clinic end generated code: checksum=badb56ed0079a6b902c9616fe068d572765b1863]*/ +/*[clinic end generated code: checksum=5b520b2416c5954a7cf0ed30955d68abe20b5868]*/ { #ifdef WITH_THREAD _PyImport_AcquireLock(); @@ -330,16 +322,12 @@ static PyObject * _imp_release_lock(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) { - PyObject *return_value = NULL; - - return_value = _imp_release_lock_impl(module); - - return return_value; + return _imp_release_lock_impl(module); } static PyObject * _imp_release_lock_impl(PyModuleDef *module) -/*[clinic end generated code: checksum=f1c2a75e3136a113184e0af2a676d5f0b5b685b4]*/ +/*[clinic end generated code: checksum=efcd9d2923294c04371596e7f6d66a706d43fcac]*/ { #ifdef WITH_THREAD if (_PyImport_ReleaseLock() < 0) { @@ -954,13 +942,13 @@ _imp__fix_co_filename_impl(PyModuleDef *module, PyCodeObject *code, PyObject *path); static PyObject * -_imp__fix_co_filename(PyModuleDef *module, PyObject *args) +_imp__fix_co_filename(PyModuleDef *module, PyObject *_args) { PyObject *return_value = NULL; PyCodeObject *code; PyObject *path; - if (!PyArg_ParseTuple(args, + if (!PyArg_ParseTuple(_args, "O!U:_fix_co_filename", &PyCode_Type, &code, &path)) goto exit; @@ -972,7 +960,7 @@ static PyObject * _imp__fix_co_filename_impl(PyModuleDef *module, PyCodeObject *code, PyObject *path) -/*[clinic end generated code: checksum=4f55bad308072b30ad1921068fc4ce85bd2b39bf]*/ +/*[clinic end generated code: checksum=59115142adadb3470604a5a99dbabcf29fa453df]*/ { update_compiled_module(code, path); @@ -1847,16 +1835,12 @@ static PyObject * _imp_extension_suffixes(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) { - PyObject *return_value = NULL; - - return_value = _imp_extension_suffixes_impl(module); - - return return_value; + return _imp_extension_suffixes_impl(module); } static PyObject * _imp_extension_suffixes_impl(PyModuleDef *module) -/*[clinic end generated code: checksum=835921e67fd698e22e101eea64839d1ad62b6451]*/ +/*[clinic end generated code: checksum=82fb35d8429a429a4dc80c84b45b1aad73ff1de7]*/ { PyObject *list; const char *suffix; @@ -1904,12 +1888,12 @@ _imp_init_builtin_impl(PyModuleDef *module, PyObject *name); static PyObject * -_imp_init_builtin(PyModuleDef *module, PyObject *args) +_imp_init_builtin(PyModuleDef *module, PyObject *_args) { PyObject *return_value = NULL; PyObject *name; - if (!PyArg_ParseTuple(args, + if (!PyArg_ParseTuple(_args, "U:init_builtin", &name)) goto exit; @@ -1921,7 +1905,7 @@ static PyObject * _imp_init_builtin_impl(PyModuleDef *module, PyObject *name) -/*[clinic end generated code: checksum=59239206e5b2fb59358066e72fd0e72e55a7baf5]*/ +/*[clinic end generated code: checksum=66c534fefd453c0da31fc9649505df0f7f7724a3]*/ { int ret; PyObject *m; @@ -1958,12 +1942,12 @@ _imp_init_frozen_impl(PyModuleDef *module, PyObject *name); static PyObject * -_imp_init_frozen(PyModuleDef *module, PyObject *args) +_imp_init_frozen(PyModuleDef *module, PyObject *_args) { PyObject *return_value = NULL; PyObject *name; - if (!PyArg_ParseTuple(args, + if (!PyArg_ParseTuple(_args, "U:init_frozen", &name)) goto exit; @@ -1975,7 +1959,7 @@ static PyObject * _imp_init_frozen_impl(PyModuleDef *module, PyObject *name) -/*[clinic end generated code: checksum=503fcc3de9961263e4d9484259af357a7d287a0b]*/ +/*[clinic end generated code: checksum=79f03f6faf4c720e67e9763398f1c13662e4d78b]*/ { int ret; PyObject *m; @@ -2012,12 +1996,12 @@ _imp_get_frozen_object_impl(PyModuleDef *module, PyObject *name); static PyObject * -_imp_get_frozen_object(PyModuleDef *module, PyObject *args) +_imp_get_frozen_object(PyModuleDef *module, PyObject *_args) { PyObject *return_value = NULL; PyObject *name; - if (!PyArg_ParseTuple(args, + if (!PyArg_ParseTuple(_args, "U:get_frozen_object", &name)) goto exit; @@ -2029,7 +2013,7 @@ static PyObject * _imp_get_frozen_object_impl(PyModuleDef *module, PyObject *name) -/*[clinic end generated code: checksum=7a6423a4daf139496b9a394ff3ac6130089d1cba]*/ +/*[clinic end generated code: checksum=3f5a715cf8898d60804d5d741838e1a7e22267c2]*/ { return get_frozen_object(name); } @@ -2054,12 +2038,12 @@ _imp_is_frozen_package_impl(PyModuleDef *module, PyObject *name); static PyObject * -_imp_is_frozen_package(PyModuleDef *module, PyObject *args) +_imp_is_frozen_package(PyModuleDef *module, PyObject *_args) { PyObject *return_value = NULL; PyObject *name; - if (!PyArg_ParseTuple(args, + if (!PyArg_ParseTuple(_args, "U:is_frozen_package", &name)) goto exit; @@ -2071,7 +2055,7 @@ static PyObject * _imp_is_frozen_package_impl(PyModuleDef *module, PyObject *name) -/*[clinic end generated code: checksum=dc7e361ea30b6945b8bbe7266d7b9a5ea433b510]*/ +/*[clinic end generated code: checksum=75b23ef8b4c0572826c72c59299f9b8239fab977]*/ { return is_frozen_package(name); } @@ -2096,12 +2080,12 @@ _imp_is_builtin_impl(PyModuleDef *module, PyObject *name); static PyObject * -_imp_is_builtin(PyModuleDef *module, PyObject *args) +_imp_is_builtin(PyModuleDef *module, PyObject *_args) { PyObject *return_value = NULL; PyObject *name; - if (!PyArg_ParseTuple(args, + if (!PyArg_ParseTuple(_args, "U:is_builtin", &name)) goto exit; @@ -2113,7 +2097,7 @@ static PyObject * _imp_is_builtin_impl(PyModuleDef *module, PyObject *name) -/*[clinic end generated code: checksum=353938c1d55210a1e3850d3ccba7539d02165cac]*/ +/*[clinic end generated code: checksum=369ea09d182be3cd7eeb630e358bb7a2deb6b3c7]*/ { return PyLong_FromLong(is_builtin(name)); } @@ -2138,12 +2122,12 @@ _imp_is_frozen_impl(PyModuleDef *module, PyObject *name); static PyObject * -_imp_is_frozen(PyModuleDef *module, PyObject *args) +_imp_is_frozen(PyModuleDef *module, PyObject *_args) { PyObject *return_value = NULL; PyObject *name; - if (!PyArg_ParseTuple(args, + if (!PyArg_ParseTuple(_args, "U:is_frozen", &name)) goto exit; @@ -2155,7 +2139,7 @@ static PyObject * _imp_is_frozen_impl(PyModuleDef *module, PyObject *name) -/*[clinic end generated code: checksum=978b547ddcb76fa6c4a181ad53569c9acf382c7b]*/ +/*[clinic end generated code: checksum=f4861aae1fc12697bf7b7be923458ef5c49c5941]*/ { const struct _frozen *p; @@ -2187,14 +2171,14 @@ _imp_load_dynamic_impl(PyModuleDef *module, PyObject *name, PyObject *path, PyObject *file); static PyObject * -_imp_load_dynamic(PyModuleDef *module, PyObject *args) +_imp_load_dynamic(PyModuleDef *module, PyObject *_args) { PyObject *return_value = NULL; PyObject *name; PyObject *path; PyObject *file = NULL; - if (!PyArg_ParseTuple(args, + if (!PyArg_ParseTuple(_args, "UO&|O:load_dynamic", &name, PyUnicode_FSDecoder, &path, &file)) goto exit; @@ -2206,7 +2190,7 @@ static PyObject * _imp_load_dynamic_impl(PyModuleDef *module, PyObject *name, PyObject *path, PyObject *file) -/*[clinic end generated code: checksum=6795f65d9ce003ccaf08e4e8eef484dc52e262d0]*/ +/*[clinic end generated code: checksum=f6de47c3fd34c1ebfddd5a5f291145bb6a540ede]*/ { PyObject *mod; FILE *fp; diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -16,12 +16,14 @@ import io import itertools import os +import pprint import re import shlex import sys import tempfile import textwrap import traceback +import uuid # TODO: # @@ -86,10 +88,13 @@ return append, output -def fail(*args, filename=None, line_number=None): +def warn_or_fail(fail=False, *args, filename=None, line_number=None): joined = " ".join([str(a) for a in args]) add, output = text_accumulator() - add("Error") + if fail: + add("Error") + else: + add("Warning") if clinic: if filename is None: filename = clinic.filename @@ -102,8 +107,15 @@ add(':\n') add(joined) print(output()) - sys.exit(-1) - + if fail: + sys.exit(-1) + + +def warn(*args, filename=None, line_number=None): + return warn_or_fail(False, *args, filename=filename, line_number=line_number) + +def fail(*args, filename=None, line_number=None): + return warn_or_fail(True, *args, filename=filename, line_number=line_number) def quoted_for_c_string(s): @@ -119,16 +131,14 @@ def is_legal_py_identifier(s): return all(is_legal_c_identifier(field) for field in s.split('.')) -# though it's called c_keywords, really it's a list of parameter names -# that are okay in Python but aren't a good idea in C. so if they're used -# Argument Clinic will add "_value" to the end of the name in C. -# (We added "args", "type", "module", "self", "cls", and "null" -# just to be safe, even though they're not C keywords.) +# identifiers that are okay in Python but aren't a good idea in C. +# so if they're used Argument Clinic will add "_value" to the end +# of the name in C. c_keywords = set(""" -args asm auto break case char cls const continue default do double +asm auto break case char cls const continue default do double else enum extern float for goto if inline int long module null register return self short signed sizeof static struct switch -type typedef typeof union unsigned void volatile while +typedef typeof union unsigned void volatile while """.strip().split()) def ensure_legal_c_identifier(s): @@ -190,6 +200,47 @@ return output()[:-1] +def indent_all_lines(s, prefix): + """ + Returns 's', with 'prefix' prepended to all lines. + + If the last line is empty, prefix is not prepended + to it. (If s is blank, returns s unchanged.) + + (textwrap.indent only adds to non-blank lines.) + """ + split = s.split('\n') + last = split.pop() + final = [] + for line in split: + final.append(prefix) + final.append(line) + final.append('\n') + if last: + final.append(prefix) + final.append(last) + return ''.join(final) + +def suffix_all_lines(s, suffix): + """ + Returns 's', with 'suffix' appended to all lines. + + If the last line is empty, suffix is not appended + to it. (If s is blank, returns s unchanged.) + """ + split = s.split('\n') + last = split.pop() + final = [] + for line in split: + final.append(line) + final.append(suffix) + final.append('\n') + if last: + final.append(last) + final.append(suffix) + return ''.join(final) + + def version_splitter(s): """Splits a version string into a tuple of integers. @@ -281,7 +332,7 @@ checksum_line = "" @abc.abstractmethod - def render(self, block): + def render(self, clinic, signatures): pass def validate(self): @@ -378,14 +429,14 @@ stop_line = "[{dsl_name} start generated code]*/" checksum_line = "/*[{dsl_name} end generated code: checksum={checksum}]*/" - def render(self, signatures): + def render(self, clinic, signatures): function = None for o in signatures: if isinstance(o, Function): if function: fail("You may specify at most one function per block.\nFound a block containing at least two:\n\t" + repr(function) + " and " + repr(o)) function = o - return self.render_function(function) + return self.render_function(clinic, function) def docstring_for_c_string(self, f): text, add, output = _text_accumulator() @@ -399,32 +450,91 @@ add('"') return ''.join(text) - impl_prototype_template = "{c_basename}_impl({impl_parameters})" - - @staticmethod - def template_base(*args): - # HACK suppress methoddef define for METHOD_NEW and METHOD_INIT - base = """ + + def output_templates(self, f): + parameters = list(f.parameters.values()) + converters = [p.converter for p in parameters] + + has_option_groups = parameters and (parameters[0].group or parameters[-1].group) + default_return_converter = (not f.return_converter or + f.return_converter.type == 'PyObject *') + + positional = parameters and (parameters[-1].kind == inspect.Parameter.POSITIONAL_ONLY) + all_boring_objects = False # yes, this will be false if there are 0 parameters, it's fine + first_optional = len(parameters) + for i, p in enumerate(parameters): + c = p.converter + if type(c) != object_converter: + break + if c.format_unit != 'O': + break + if p.default is not unspecified: + first_optional = min(first_optional, i) + else: + all_boring_objects = True + + meth_o = (len(parameters) == 1 and + parameters[0].kind == inspect.Parameter.POSITIONAL_ONLY and + not converters[0].is_optional() and + isinstance(converters[0], object_converter) and + converters[0].format_unit == 'O') + + + # we have to set seven things before we're done: + # + # docstring_prototype + # docstring_definition + # impl_prototype + # methoddef_define + # parser_prototype + # parser_definition + # impl_definition + # + # since impl_prototype is always just impl_definition + ';' + # we just define impl_definition at the top + + docstring_prototype = "PyDoc_VAR({c_basename}__doc__);" + + docstring_definition = """ PyDoc_STRVAR({c_basename}__doc__, {docstring}); -""" - - if args[-1] == None: - return base - - flags = '|'.join(f for f in args if f) - return base + """ -#define {methoddef_name} \\ - {{"{name}", (PyCFunction){c_basename}, {methoddef_flags}, {c_basename}__doc__}}, -""".replace('{methoddef_flags}', flags) - - def meth_noargs_template(self, methoddef_flags=""): - return self.template_base("METH_NOARGS", methoddef_flags) + """ +""".strip() + + impl_definition = """ static {impl_return_type} -{impl_prototype}; - +{c_basename}_impl({impl_parameters})""".strip() + + impl_prototype = parser_prototype = parser_definition = None + + def meth_varargs(): + nonlocal flags + nonlocal parser_prototype + + flags = "METH_VARARGS" + + parser_prototype = """ +static PyObject * +{c_basename}({self_type}{self_name}, PyObject *_args) +""".strip() + + if not parameters: + # no parameters, METH_NOARGS + + flags = "METH_NOARGS" + + parser_prototype = """ static PyObject * {c_basename}({self_type}{self_name}, PyObject *Py_UNUSED(ignored)) +""".strip() + + if default_return_converter: + parser_definition = parser_prototype + """ +{{ + return {c_basename}_impl({impl_arguments}); +}} +""".rstrip() + else: + parser_definition = parser_prototype + """ {{ PyObject *return_value = NULL; {declarations} @@ -437,28 +547,43 @@ {cleanup} return return_value; }} - -static {impl_return_type} -{impl_prototype} -""" - - def meth_o_template(self, methoddef_flags=""): - return self.template_base("METH_O", methoddef_flags) + """ +""".rstrip() + + elif meth_o: + if default_return_converter: + # maps perfectly to METH_O, doesn't need a return converter, + # so we skip the parse function and call + # directly into the impl function + + # SLIGHT HACK + # METH_O uses {impl_parameters} for the parser. + + flags = "METH_O" + + impl_definition = """ static PyObject * {c_basename}({impl_parameters}) -""" - - def meth_o_return_converter_template(self, methoddef_flags=""): - return self.template_base("METH_O", methoddef_flags) + """ -static {impl_return_type} -{impl_prototype}; - +""".strip() + + impl_prototype = parser_prototype = parser_definition = '' + + else: + # SLIGHT HACK + # METH_O uses {impl_parameters} for the parser. + + flags = "METH_O" + + parser_prototype = """ static PyObject * {c_basename}({impl_parameters}) +""".strip() + + parser_definition = parser_prototype + """ {{ PyObject *return_value = NULL; {declarations} {initializers} + _return_value = {c_basename}_impl({impl_arguments}); {return_conversion} @@ -466,18 +591,16 @@ {cleanup} return return_value; }} - -static {impl_return_type} -{impl_prototype} -""" - - def option_group_template(self, methoddef_flags=""): - return self.template_base("METH_VARARGS", methoddef_flags) + """ -static {impl_return_type} -{impl_prototype}; - -static PyObject * -{c_basename}({self_type}{self_name}, PyObject *args) +""".rstrip() + + elif has_option_groups: + # positional parameters with option groups + # (we have to generate lots of PyArg_ParseTuple calls + # in a big switch statement) + + meth_varargs() + + parser_definition = parser_prototype + """ {{ PyObject *return_value = NULL; {declarations} @@ -491,67 +614,138 @@ {cleanup} return return_value; }} - -static {impl_return_type} -{impl_prototype} -""" - - def keywords_template(self, methoddef_flags=""): - return self.template_base("METH_VARARGS|METH_KEYWORDS", methoddef_flags) + """ -static {impl_return_type} -{impl_prototype}; - +""".rstrip() + + elif positional and all_boring_objects: + # positional-only, but no option groups, + # and nothing but normal objects: + # PyArg_UnpackTuple! + + meth_varargs() + + # substitute in the min and max by hand right here + assert parameters + min_o = first_optional + max_o = len(parameters) + if isinstance(parameters[0].converter, self_converter): + min_o -= 1 + max_o -= 1 + min_o = str(min_o) + max_o = str(max_o) + + parser_definition = parser_prototype + """ +{{ + PyObject *return_value = NULL; + {declarations} + {initializers} + + if (!PyArg_UnpackTuple(_args, "{name}", + {min}, {max}, + {parse_arguments})) + goto exit; + {return_value} = {c_basename}_impl({impl_arguments}); + {return_conversion} + +exit: + {cleanup} + return return_value; +}} +""".rstrip().replace('{min}', min_o).replace('{max}', max_o) + + elif positional: + # positional-only, but no option groups + # we only need one call to PyArg_ParseTuple + + meth_varargs() + + parser_definition = parser_prototype + """ +{{ + PyObject *return_value = NULL; + {declarations} + {initializers} + + if (!PyArg_ParseTuple(_args, + "{format_units}:{name}", + {parse_arguments})) + goto exit; + {return_value} = {c_basename}_impl({impl_arguments}); + {return_conversion} + +exit: + {cleanup} + return return_value; +}} +""".rstrip() + + else: + # positional-or-keyword arguments + flags = "METH_VARARGS|METH_KEYWORDS" + + parser_prototype = """ static PyObject * -{c_basename}({self_type}{self_name}, PyObject *args, PyObject *kwargs) +{c_basename}({self_type}{self_name}, PyObject *_args, PyObject *_kwargs) +""".strip() + + parser_definition = parser_prototype + """ {{ PyObject *return_value = NULL; static char *_keywords[] = {{{keywords}, NULL}}; {declarations} {initializers} - if (!PyArg_ParseTupleAndKeywords(args, kwargs, + if (!PyArg_ParseTupleAndKeywords(_args, _kwargs, "{format_units}:{name}", _keywords, {parse_arguments})) goto exit; {return_value} = {c_basename}_impl({impl_arguments}); {return_conversion} -{exit_label} +exit: {cleanup} return return_value; }} - -static {impl_return_type} -{impl_prototype} -""" - - def positional_only_template(self, methoddef_flags=""): - return self.template_base("METH_VARARGS", methoddef_flags) + """ -static {impl_return_type} -{impl_prototype}; - -static PyObject * -{c_basename}({self_type}{self_name}, PyObject *args) -{{ - PyObject *return_value = NULL; - {declarations} - {initializers} - - if (!PyArg_ParseTuple(args, - "{format_units}:{name}", - {parse_arguments})) - goto exit; - {return_value} = {c_basename}_impl({impl_arguments}); - {return_conversion} - -{exit_label} - {cleanup} - return return_value; -}} - -static {impl_return_type} -{impl_prototype} -""" +""".rstrip() + + if f.methoddef_flags: + assert flags + flags += '|' + f.methoddef_flags + + methoddef_define = """ +#define {methoddef_name} \\ + {{"{name}", (PyCFunction){c_basename}, {methoddef_flags}, {c_basename}__doc__}}, +""".strip().replace('{methoddef_flags}', flags) + + # parser_prototype mustn't be None, but it could be an empty string. + assert parser_prototype is not None + assert not parser_prototype.endswith(';') + + if parser_prototype: + parser_prototype += ';' + + assert impl_definition + if impl_prototype is None: + impl_prototype = impl_definition + ";" + + # __new__ and __init__ don't need methoddefs + if f.kind in (METHOD_NEW, METHOD_INIT): + methoddef_define = '' + + d = { + "docstring_prototype" : docstring_prototype, + "docstring_definition" : docstring_definition, + "impl_prototype" : impl_prototype, + "methoddef_define" : methoddef_define, + "parser_prototype" : parser_prototype, + "parser_definition" : parser_definition, + "impl_definition" : impl_definition, + } + + d2 = {} + for name, value in d.items(): + if value: + value = '\n' + value + '\n' + d2[name] = value + return d2 @staticmethod def group_to_variable_name(group): @@ -603,7 +797,7 @@ count_min = sys.maxsize count_max = -1 - add("switch (PyTuple_GET_SIZE(args)) {{\n") + add("switch (PyTuple_GET_SIZE(_args)) {{\n") for subset in permute_optional_groups(left, required, right): count = len(subset) count_min = min(count_min, count) @@ -633,7 +827,7 @@ s = """ case {count}: - if (!PyArg_ParseTuple(args, "{format_units}:{name}", {parse_arguments})) + if (!PyArg_ParseTuple(_args, "{format_units}:{name}", {parse_arguments})) return NULL; {group_booleans} break; @@ -649,7 +843,7 @@ add("}}") template_dict['option_group_parsing'] = output() - def render_function(self, f): + def render_function(self, clinic, f): if not f: return "" @@ -705,6 +899,27 @@ if has_option_groups and (not positional): fail("You cannot use optional groups ('[' and ']')\nunless all parameters are positional-only ('/').") + # HACK + # when we're METH_O, but have a custom + # return converter, we use + # "impl_parameters" for the parsing + # function because that works better. + # but that means we must supress actually + # declaring the impl's parameters as variables + # in the parsing function. but since it's + # METH_O, we only have one anyway, so we don't + # have any problem finding it. + default_return_converter = (not f.return_converter or + f.return_converter.type == 'PyObject *') + if (len(parameters) == 1 and + parameters[0].kind == inspect.Parameter.POSITIONAL_ONLY and + not converters[0].is_optional() and + isinstance(converters[0], object_converter) and + converters[0].format_unit == 'O' and + not default_return_converter): + + data.declarations.pop(0) + # now insert our "self" (or whatever) parameters # (we deliberately don't call render on self converters) stock_self = self_converter('self', f) @@ -731,63 +946,41 @@ template_dict['cleanup'] = "".join(data.cleanup) template_dict['return_value'] = data.return_value - template_dict['impl_prototype'] = self.impl_prototype_template.format_map(template_dict) - - default_return_converter = (not f.return_converter or - f.return_converter.type == 'PyObject *') - - if not parameters: - template = self.meth_noargs_template(f.methoddef_flags) - elif (len(parameters) == 1 and - parameters[0].kind == inspect.Parameter.POSITIONAL_ONLY and - not converters[0].is_optional() and - isinstance(converters[0], object_converter) and - converters[0].format_unit == 'O'): - if default_return_converter: - template = self.meth_o_template(f.methoddef_flags) - else: - # HACK - # we're using "impl_parameters" for the - # non-impl function, because that works - # better for METH_O. but that means we - # must supress actually declaring the - # impl's parameters as variables in the - # non-impl. but since it's METH_O, we - # only have one anyway, so - # we don't have any problem finding it. - declarations_copy = list(data.declarations) - before, pyobject, after = declarations_copy[0].partition('PyObject *') - assert not before, "hack failed, see comment" - assert pyobject, "hack failed, see comment" - assert after and after[0].isalpha(), "hack failed, see comment" - del declarations_copy[0] - template_dict['declarations'] = "\n".join(declarations_copy) - template = self.meth_o_return_converter_template(f.methoddef_flags) - elif has_option_groups: + if has_option_groups: self.render_option_group_parsing(f, template_dict) - template = self.option_group_template(f.methoddef_flags) + + templates = self.output_templates(f) + + for name, destination in clinic.field_destinations.items(): + template = templates[name] + if has_option_groups: + template = linear_format(template, + option_group_parsing=template_dict['option_group_parsing']) template = linear_format(template, - option_group_parsing=template_dict['option_group_parsing']) - elif positional: - template = self.positional_only_template(f.methoddef_flags) - else: - template = self.keywords_template(f.methoddef_flags) - - template = linear_format(template, - declarations=template_dict['declarations'], - return_conversion=template_dict['return_conversion'], - initializers=template_dict['initializers'], - cleanup=template_dict['cleanup'], - ) - - # Only generate the "exit:" label - # if we have any gotos - need_exit_label = "goto exit;" in template - template = linear_format(template, - exit_label="exit:" if need_exit_label else '' - ) - - return template.format_map(template_dict) + declarations=template_dict['declarations'], + return_conversion=template_dict['return_conversion'], + initializers=template_dict['initializers'], + cleanup=template_dict['cleanup'], + ) + + # Only generate the "exit:" label + # if we have any gotos + need_exit_label = "goto exit;" in template + template = linear_format(template, + exit_label="exit:" if need_exit_label else '' + ) + + s = template.format_map(template_dict) + + if clinic.line_prefix: + s = indent_all_lines(s, clinic.line_prefix) + if clinic.line_suffix: + s = suffix_all_lines(s, clinic.line_suffix) + + destination.append(s) + + return clinic.get_destination('block').dump() + @contextlib.contextmanager @@ -889,19 +1082,27 @@ self.last_checksum_re = None self.last_dsl_name = None self.dsl_name = None + self.first_block = True def __iter__(self): return self def __next__(self): - if not self.input: - raise StopIteration - - if self.dsl_name: - return_value = self.parse_clinic_block(self.dsl_name) - self.dsl_name = None - return return_value - return self.parse_verbatim_block() + while True: + if not self.input: + raise StopIteration + + if self.dsl_name: + return_value = self.parse_clinic_block(self.dsl_name) + self.dsl_name = None + self.first_block = False + return return_value + block = self.parse_verbatim_block() + if self.first_block and not block.input: + continue + self.first_block = False + return block + def is_start_line(self, line): match = self.start_re.match(line.lstrip()) @@ -980,7 +1181,8 @@ if checksum != computed: fail("Checksum mismatch!\nExpected: {}\nComputed: {}\n" "Suggested fix: remove all generated code including " - "the end marker, or use the '-f' option." + "the end marker,\n" + "or use the '-f' option." .format(checksum, computed)) else: # put back output @@ -1025,15 +1227,62 @@ write(self.language.stop_line.format(dsl_name=dsl_name)) write("\n") - output = block.output + output = ''.join(block.output) if output: + if not output.endswith('\n'): + output += '\n' write(output) - if not output.endswith('\n'): - write('\n') write(self.language.checksum_line.format(dsl_name=dsl_name, checksum=compute_checksum(output))) write("\n") + def write(self, text): + self.f.write(text) + + +class Destination: + def __init__(self, name, type, clinic, *args): + self.name = name + self.type = type + self.clinic = clinic + valid_types = ('buffer', 'file', 'suppress', 'two-pass') + if type not in valid_types: + fail("Invalid destination type " + repr(type) + " for " + name + " , must be " + ', '.join(valid_types)) + extra_arguments = 1 if type == "file" else 0 + if len(args) < extra_arguments: + fail("Not enough arguments for destination " + name + " new " + type) + if len(args) > extra_arguments: + fail("Too many arguments for destination " + name + " new " + type) + if type =='file': + d = {} + d['filename'] = filename = clinic.filename + d['basename'], d['extension'] = os.path.splitext(filename) + self.filename = args[0].format_map(d) + if type == 'two-pass': + self.id = None + + self.text, self.append, self._dump = _text_accumulator() + + def __repr__(self): + if self.type == 'file': + file_repr = " " + repr(self.filename) + else: + file_repr = '' + return "".join(("")) + + def clear(self): + if self.type != 'buffer': + fail("Can't clear destination" + self.name + " , it's not of type buffer") + self.text.clear() + + def dump(self): + if self.type == 'two-pass': + if self.id is None: + self.id = str(uuid.uuid4()) + return self.id + fail("You can only dump a two-pass buffer exactly once!") + return self._dump() + # maps strings to Language objects. # "languages" maps the name of the language ("C", "Python"). @@ -1071,6 +1320,8 @@ # (instantiated from the "parsers" global.) self.parsers = {} self.language = language + if printer: + fail("Custom printers are broken right now") self.printer = printer or BlockPrinter(language) self.verify = verify self.filename = filename @@ -1078,9 +1329,100 @@ self.classes = collections.OrderedDict() self.functions = [] + self.line_prefix = self.line_suffix = '' + + self.destinations = {} + self.add_destination("block", "buffer") + self.add_destination("suppress", "suppress") + self.add_destination("buffer", "buffer") + self.add_destination("two-pass", "two-pass") + if filename: + self.add_destination("file", "file", "{basename}.clinic{extension}") + + d = self.destinations.get + self.field_destinations = collections.OrderedDict(( + ('docstring_prototype', d('suppress')), + ('docstring_definition', d('block')), + ('methoddef_define', d('block')), + ('impl_prototype', d('block')), + ('parser_prototype', d('suppress')), + ('parser_definition', d('block')), + ('impl_definition', d('block')), + )) + + presets_text = """ +preset original +everything block +docstring_prototype suppress +parser_prototype suppress + +preset file +everything file +docstring_prototype suppress +parser_prototype suppress +impl_definition block + +preset buffer +everything buffer +docstring_prototype suppress +impl_prototype suppress +parser_prototype suppress +impl_definition block + +preset partial-buffer +everything buffer +docstring_prototype block +impl_prototype suppress +methoddef_define block +parser_prototype block +impl_definition block + +preset two-pass +everything buffer +docstring_prototype two-pass +impl_prototype suppress +methoddef_define two-pass +parser_prototype two-pass +impl_definition block + +""" + self.presets = {} + preset = None + for line in presets_text.strip().split('\n'): + line = line.strip() + if not line: + continue + name, value = line.split() + if name == 'preset': + self.presets[value] = preset = collections.OrderedDict() + continue + + destination = self.get_destination(value) + + if name == 'everything': + for name in self.field_destinations: + preset[name] = destination + continue + + assert name in self.field_destinations + preset[name] = destination + global clinic clinic = self + def get_destination(self, name, default=unspecified): + d = self.destinations.get(name) + if not d: + if default is not unspecified: + return default + fail("Destination does not exist: " + repr(name)) + return d + + def add_destination(self, name, type, *args): + if name in self.destinations: + fail("Destination already exists: " + repr(name)) + self.destinations[name] = Destination(name, type, self, *args) + def parse(self, input): printer = self.printer self.block_parser = BlockParser(input, self.language, verify=self.verify) @@ -1097,7 +1439,66 @@ fail('Exception raised during parsing:\n' + traceback.format_exc().rstrip()) printer.print_block(block) - return printer.f.getvalue() + + second_pass_replacements = {} + + for name, destination in self.destinations.items(): + if destination.type == 'suppress': + continue + output = destination._dump() + + if destination.type == 'two-pass': + if destination.id: + second_pass_replacements[destination.id] = output + elif output: + fail("Two-pass buffer " + repr(name) + " not empty at end of file!") + continue + + if output: + + block = Block("", dsl_name="clinic", output=output) + + if destination.type == 'buffer': + block.input = "dump " + name + "\n" + warn("Destination buffer " + repr(name) + " not empty at end of file, emptying.") + printer.write("\n") + printer.print_block(block) + continue + + if destination.type == 'file': + try: + with open(destination.filename, "rt") as f: + parser_2 = BlockParser(f.read(), language=self.language) + blocks = list(parser_2) + if (len(blocks) != 1) or (blocks[0].input != 'preserve\n'): + fail("Modified destination file " + repr(destination.filename) + ", not overwriting!") + except FileNotFoundError: + pass + + block.input = 'preserve\n' + printer_2 = BlockPrinter(self.language) + printer_2.print_block(block) + with open(destination.filename, "wt") as f: + f.write(printer_2.f.getvalue()) + continue + text = printer.f.getvalue() + + if second_pass_replacements: + printer_2 = BlockPrinter(self.language) + parser_2 = BlockParser(text, self.language) + changed = False + for block in parser_2: + if block.dsl_name: + for id, replacement in second_pass_replacements.items(): + if id in block.output: + changed = True + block.output = block.output.replace(id, replacement) + printer_2.print_block(block) + if changed: + text = printer_2.f.getvalue() + + return text + def _module_and_class(self, fields): """ @@ -2195,6 +2596,7 @@ self.kind = CALLABLE self.coexist = False self.parameter_continuation = '' + self.preserve_output = False def directive_version(self, required): global version @@ -2226,6 +2628,56 @@ module.classes[name] = c self.block.signatures.append(c) + def directive_set(self, name, value): + if name not in ("line_prefix", "line_suffix"): + fail("unknown variable", repr(name)) + + value = value.format_map({ + 'block comment start': '/*', + 'block comment end': '*/', + }) + + self.clinic.__dict__[name] = value + + def directive_destination(self, name, command, *args): + if command is 'new': + self.clinic.add_destination(name, command, *args) + return + + if command is 'clear': + self.clinic.get_destination(name).clear() + fail("unknown destination command", repr(command)) + + + def directive_output(self, field, destination): + fd = self.clinic.field_destinations + + if field == "preset": + preset = self.clinic.presets.get(destination) + if not preset: + fail("Unknown preset " + repr(destination) + "!") + fd.update(preset) + return + + d = self.clinic.get_destination(destination) + + if field == "everything": + for name in list(fd): + fd[name] = d + return + + if field not in fd: + fail("Invalid field " + repr(field) + ", must be one of:\n " + ", ".join(valid_fields)) + fd[field] = d + + def directive_dump(self, name): + self.block.output.append(self.clinic.get_destination(name).dump()) + + def directive_preserve(self): + if self.preserve_output: + fail("Can't have preserve twice in one block!") + self.preserve_output = True + def at_classmethod(self): if self.kind is not CALLABLE: fail("Can't set @classmethod, function is not a normal callable") @@ -2241,10 +2693,11 @@ fail("Called @coexist twice!") self.coexist = True - def parse(self, block): self.reset() self.block = block + self.saved_output = self.block.output + block.output = [] block_start = self.clinic.block_parser.line_number lines = block.input.split('\n') for line_number, line in enumerate(lines, self.clinic.block_parser.block_start_line_number): @@ -2255,7 +2708,12 @@ self.next(self.state_terminal) self.state(None) - block.output = self.clinic.language.render(block.signatures) + block.output.extend(self.clinic.language.render(clinic, block.signatures)) + + if self.preserve_output: + if block.output: + fail("'preserve' only works for blocks that don't produce any output!") + block.output = self.saved_output @staticmethod def ignore_line(line): @@ -2313,7 +2771,10 @@ directive_name = fields[0] directive = self.directives.get(directive_name, None) if directive: - directive(*fields[1:]) + try: + directive(*fields[1:]) + except TypeError as e: + fail(str(e)) return # are we cloning? @@ -2439,8 +2900,6 @@ # with X spaces such that F < X < P. (As before, F is the indent # of the function declaration.) # - ############## - # # Also, currently Argument Clinic places the following restrictions on groups: # * Each group must contain at least one parameter. # * Each group may contain at most one group, which must be the furthest @@ -3063,20 +3522,6 @@ s = parameter_name parameters.append(s) print(' {}({})'.format(short_name, ', '.join(parameters))) - # add_comma = False - # for parameter_name, parameter in signature.parameters.items(): - # if parameter.kind == inspect.Parameter.KEYWORD_ONLY: - # if add_comma: - # parameters.append(', ') - # else: - # add_comma = True - # s = parameter_name - # if parameter.default != inspect.Parameter.empty: - # s += '=' + repr(parameter.default) - # parameters.append(s) - # parameters.append(')') - - # print(" ", short_name + "".join(parameters)) print() print("All converters also accept (c_default=None, py_default=None, annotation=None).") print("All return converters also accept (py_default=None).") diff --git a/Tools/clinic/clinic_test.py b/Tools/clinic/clinic_test.py --- a/Tools/clinic/clinic_test.py +++ b/Tools/clinic/clinic_test.py @@ -34,6 +34,8 @@ def get(self, name, default): return self.used_converters.setdefault(name, FakeConverterFactory(name)) +c = clinic.Clinic(language='C') + class FakeClinic: def __init__(self): self.converters = FakeConvertersDict() @@ -44,6 +46,31 @@ self.modules = collections.OrderedDict() clinic.clinic = self self.name = "FakeClinic" + self.line_prefix = self.line_suffix = '' + self.destinations = {} + self.add_destination("block", "buffer") + self.add_destination("suppress", "suppress") + d = self.destinations.get + self.field_destinations = collections.OrderedDict(( + ('docstring_prototype', d('suppress')), + ('docstring_definition', d('block')), + ('methoddef_define', d('block')), + ('impl_prototype', d('block')), + ('parser_prototype', d('suppress')), + ('parser_definition', d('block')), + ('impl_definition', d('block')), + )) + + def get_destination(self, name): + d = self.destinations.get(name) + if not d: + sys.exit("Destination does not exist: " + repr(name)) + return d + + def add_destination(self, name, type, *args): + if name in self.destinations: + sys.exit("Destination already exists: " + repr(name)) + self.destinations[name] = clinic.Destination(name, type, self, *args) def is_directive(self, name): return name == "module"