diff options
Diffstat (limited to 'sources/shiboken2/libshiboken/signature.cpp')
-rw-r--r-- | sources/shiboken2/libshiboken/signature.cpp | 80 |
1 files changed, 3 insertions, 77 deletions
diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp index df49a4d29..f0bb8e609 100644 --- a/sources/shiboken2/libshiboken/signature.cpp +++ b/sources/shiboken2/libshiboken/signature.cpp @@ -42,77 +42,13 @@ extern "C" { -/*************************************************************************** - *************************************************************************** - - - The signature C extension - ========================= - - This module is a C extension for CPython 3.4 and up, and CPython 2.7. - It's purpose is to provide support for the __signature__ attribute - of builtin PyCFunction objects. - - - Short excursion on the topic - ---------------------------- - - Beginning with CPython 3.5, Python functions began to grow a __signature__ - attribute for normal Python functions. This is totally optional and just - a nice-to-have feature in Python. - - PySide, on the other hand, could use __signature__ very much, because the - typing info for the 14000+ PySide functions is really missing, and it - would be nice to have this info available directly in Python. - - - How this code works - ------------------- - - The basic idea is to create a dummy Python function and to use the inspect - module to create a signature object. Then, this object is returned as the - result of the __signature__ attribute of the real PyCFunction. - - There is one thing that really changes Python a bit: - - I added the __signature__ attribute to every function. - - That is a little change to Python that does not harm, but it saves us - tons of code, that was needed in the former versions. - - The internal work is done in two steps: - All functions get their "signature text" when the module is imported. - The actual signature is created later, when the attribute is really used. - - Example: - - The PyCFunction 'QtWidgets.QApplication.palette' is interrogated for its - signature. That means 'pyside_sm_get___signature__()' is called. - It calls GetSignature_Function which returns the signature if it is found. - - There are actually 2 locations where late initialization occurs: - - 'dict' can be no dict but a tuple. That is the argument tuple that - was saved by 'PySide_BuildSignatureArgs' at module load time. - If so, then 'pyside_type_init' in 'signature.py' will be called, - which parses the string and creates the dict. - - 'props' can be empty. Then 'create_signature' in 'signature_loader.py' - is called, which uses a dummy function to produce a signature instance - with the inspect module. - - This module is dedicated to our lovebird "PĆ¼ppi", who died on 2017-09-15. - - **************************************************************************** - ****************************************************************************/ +/* + * The documentation is located in file signature_doc.rst + */ #include "signature.h" #include <structmember.h> -#define EXTENSION_ENABLED \ - PY_VERSION_HEX >= 0x03040000 || \ - (PY_VERSION_HEX < 0x03000000 && PY_VERSION_HEX >= 0x02070000) - -#if EXTENSION_ENABLED - // These constants were needed in former versions of the module: #define PYTHON_HAS_QUALNAME (PY_VERSION_HEX >= 0x03030000) #define PYTHON_HAS_UNICODE (PY_VERSION_HEX >= 0x03000000) @@ -697,20 +633,14 @@ PySide_BuildSignatureProps(PyObject *classmod) return dict; } -#endif // EXTENSION_ENABLED - int SbkSpecial_Type_Ready(PyObject *module, PyTypeObject *type, const char *signatures) { int ret; -#if EXTENSION_ENABLED if (PySideType_Ready(type) < 0) return -1; ret = PySide_BuildSignatureArgs(module, (PyObject *)type, signatures); -#else - ret = PyType_Ready(type); -#endif if (ret < 0) { PyErr_Print(); PyErr_SetNone(PyExc_ImportError); @@ -718,7 +648,6 @@ SbkSpecial_Type_Ready(PyObject *module, PyTypeObject *type, return ret; } -#if EXTENSION_ENABLED static int PySide_FinishSignatures(PyObject *module, const char *signatures) { @@ -765,17 +694,14 @@ PySide_FinishSignatures(PyObject *module, const char *signatures) } return 0; } -#endif // EXTENSION_ENABLED void FinishSignatureInitialization(PyObject *module, const char *signatures) { -#if EXTENSION_ENABLED if (PySide_FinishSignatures(module, signatures) < 0) { PyErr_Print(); PyErr_SetNone(PyExc_ImportError); } -#endif } } //extern "C" |