Details
Description
PySide already has a quite useful introspection feature:
When you call a function with the right number of parameters, but the wrong argument types, you get a nice error display like so:
$ python3 Python 3.6.1 (default, Apr 4 2017, 09:40:21) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from PySide2.QtWidgets import QApplication >>> QApplication([]).palette(42) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'PySide2.QtWidgets.QApplication.palette' called with wrong argument types: PySide2.QtWidgets.QApplication.palette(int) Supported signatures: PySide2.QtWidgets.QApplication.palette(PySide2.QtWidgets.QWidget) PySide2.QtWidgets.QApplication.palette() PySide2.QtWidgets.QApplication.palette(unicode) >>>
This is not bad at all, but could become much more useful.
Drawbacks:
- The signatures are only visible if you pass the (a) right number of arguments,
- the function must be called with wrong arguments,
- the function must be called at all. We would like a way to get this info without actually calling.
Based on this existing error reporting feature, we want to implement a better one which allows for a priori introspection. With such a tool, we could easily write systematic tests and catch all common and exotic functions, which would improve our product very quickly.
Some investigation has been done in order to evaluate prior work in Python that could be used here.
In Python 3, there are two introspection concepts:
- builtin_function.__text_signature__ is computed from the __doc__ string of functions. It extracts info in a special format to create this computed attribute. Unfortunately, this approach still does not support annotations which we urgently need, and it is limited to a single signature per function.
- function.__signature__ comes with much structure and is very well suited for introspection, but unfortunately
the specification does also not provide multiple signatures per function. Also, function.__signature__ is only
meant for Python functions, not builtin functions.
Because it is not clear what to do in this situation, also finding the best way to implement this is a part of this task.
Some open questions and considerations:
- Should signatures have true type objects as their annotation results, or should they be just strings? The question comes from those functions which are there formally, but cannot be instantiated, because they are purely abstract.
- Do we re-use the Python3 __signature__ objects for our purpose and extend them to allow them to return a sequence of signature objects? Or do we invent our own __signatures__ attribute as sequence?
- Currently, only Python3 supports signatures. But there is a re-implementation of signatures for Python2 as a module. Should we use this, or take an independent approach?
- For maximum compatibility, it is maybe not the best idea to invent something that extends Python's type system like above. We could instead build a shadow type which inherits from builtin_function and has the needed attributes freely, because such a shadow type is only used inside the introspection feature. The real function remains completely unchanged.
Literature:
Attachments
Issue Links
- is required for
-
PYSIDE-156 crash in PySide2 if QApplication forgotten
- Open
- resulted in
-
PYSIDE-616 Signature parser fails for default values of template types
- Closed
For Gerrit Dashboard: PYSIDE-510 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
195186,2 | WIP: Implement introspection | 5.6 | pyside/pyside-setup | Status: ABANDONED | -2 | 0 |
195488,2 | WIP: Implement introspection | 5.6 | pyside/pyside-setup | Status: ABANDONED | -2 | 0 |
195796,21 | WIP: Implement introspection | 5.9 | pyside/pyside-setup | Status: ABANDONED | -2 | 0 |
198654,68 | Implement introspection with __signature__ package | 5.6 | pyside/pyside-setup | Status: MERGED | -2 | 0 |
200344,1 | Implement introspection with __signature__ | 5.6 | pyside/pyside-setup | Status: ABANDONED | 0 | 0 |
200549,5 | WIP: Implement introspection with __signature__ for Python 2.7 | 5.6 | pyside/pyside-setup | Status: ABANDONED | -2 | 0 |
203533,3 | WIP: Implement introspection with __signature__ with embed | dev | pyside/pyside-setup | Status: ABANDONED | -2 | 0 |
205295,1 | WIP: Implement introspection with __signature__ | 5.6 | pyside/pyside-setup | Status: ABANDONED | -2 | 0 |
206254,3 | Signature: Improve error reporting | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
206269,4 | Signature: fix documentation | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
206461,4 | Signature: Simplify parser by not reloading mapping | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
206529,2 | Signature: tiny refinement in Reloader | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
206774,3 | Signature: support the new types and constants of 5.9 | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
206962,2 | Implement introspection with __signature__ package | 5.9 | pyside/pyside-setup | Status: ABANDONED | 0 | 0 |
206963,2 | Signature: Simplify parser by not reloading mapping | 5.9 | pyside/pyside-setup | Status: ABANDONED | 0 | 0 |
206964,2 | Signature: Improve error reporting | 5.9 | pyside/pyside-setup | Status: ABANDONED | 0 | 0 |
206965,2 | Signature: fix documentation | 5.9 | pyside/pyside-setup | Status: ABANDONED | 0 | 0 |
206967,2 | Signature: support the new types and constants of 5.9 | 5.9 | pyside/pyside-setup | Status: ABANDONED | 0 | 0 |
206973,1 | Implement introspection with __signature__ package | 5.9 | pyside/pyside-setup | Status: ABANDONED | 0 | 0 |
206974,4 | Implement introspection with __signature__ package | 5.9 | pyside/pyside-setup | Status: ABANDONED | 0 | 0 |
207013,2 | Signature: support the new types and constants of 5.9 part 2 | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
207014,2 | Signature: support the new types and constants of 5.9 part 3 | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
207080,5 | Fix the signature of the Q*Application constructor | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
207256,2 | Signature: Remove pre 5.7 parts, fix coding style | 5.9 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
207340,3 | Signature: Remove post 5.6 parts, fix coding style | 5.6 | pyside/pyside-setup | Status: ABANDONED | 0 | 0 |
207341,2 | Signature: Remove post 5.6 parts, fix coding style | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
208884,16 | Update and complete the signature module | 5.6 | pyside/pyside-setup | Status: MERGED | -2 | 0 |
209638,31 | Create a function existence registry | 5.6 | pyside/pyside-setup | Status: MERGED | -2 | 0 |
211405,3 | Update and complete the signature module | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
211974,5 | Create a function existence registry | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
212478,2 | Create a function existence registry | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
212503,2 | Create a function existence registry | 5.6 | pyside/pyside-setup | Status: ABANDONED | 0 | 0 |
212553,2 | Create a function existence registry | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
212561,4 | Create a function existence registry | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
212706,2 | Create a function existence registry | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
213019,2 | Fix signature registry on Python2 with .pyc files | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
213155,4 | Fix signature registry on Python2 with .pyc files, part 2 | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
213292,10 | Unify signature registry for py2 / py3 and clean up | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
213319,1 | Fix signature registry on Python2 with .pyc files, part 2 | 5.6 | pyside/pyside-setup | Status: ABANDONED | -2 | 0 |
213334,1 | Fix signature registry on Python2 with .pyc files, part 2 last trial | 5.6 | pyside/pyside-setup | Status: ABANDONED | -2 | 0 |
215038,3 | Signature existence tests: Do not use patch version in files | 5.6 | pyside/pyside-setup | Status: ABANDONED | 0 | 0 |
215094,2 | Signature existence tests: Fall back to previous patch releases | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
215567,4 | Signature existence tests: Fix generation of the signature file | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
217474,5 | WIP: Pep384 step 7: Adjust signature.cpp to the limited API | 5.6 | pyside/pyside-setup | Status: ABANDONED | -2 | 0 |
218013,31 | PEP 384-7: Adjust signature.cpp to the limited API | 5.9 | pyside/pyside-setup | Status: ABANDONED | -2 | 0 |
218315,2 | Fix signature extension disabling | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
221229,2 | Signature parser: Bail out if splitting the argument list fails | 5.9 | pyside/pyside-setup | Status: ABANDONED | -2 | 0 |
221272,4 | Signature: make the parser more complete for 5.11 | 5.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
230082,3 | WIP: Squashed Heaptype/Limited API changes | 5.9 | pyside/pyside-setup | Status: ABANDONED | -2 | 0 |
234089,41 | Prepare the Signature Module For More Applications | 5.12 | pyside/pyside-setup | Status: MERGED | -2 | 0 |
236040,9 | Document the Signature Module | 5.11 | pyside/pyside-setup | Status: MERGED | -2 | 0 |
237838,3 | Reduce the redundant signature_test | 5.11 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
237842,3 | Make signature module unconditional | 5.11 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
238931,7 | Automate Parsing COIN testresults for exists_{platf}_{version}_ci.py | 5.11 | pyside/pyside-setup | Status: MERGED | -2 | 0 |
239911,2 | Update the Registry After Explicit Linux Naming | 5.11 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
240861,6 | Implement Different Signature Layouts | 5.12 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
242242,3 | Signature: Produce Correctly Nested Python Interfaces | 5.12 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
248300,17 | Complete The Signature Introspection | 5.12 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
255328,6 | Simplify Python Imports For Embedding | 5.12 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
259005,4 | Cleanup And Simplify the Signature Related Code | 5.12 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
312440,4 | signature: Use a clean init function to initialize it | 5.15 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
315001,5 | Signature: Revert SbkSpecial_Type_Ready to PyType_Ready | 5.15 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
315050,6 | Signature: Break the source into multiple files | 5.15 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
315781,2 | WIP: Signature: Support 'getset_descriptor' | 5.15 | pyside/pyside-setup | Status: ABANDONED | -2 | 0 |
320710,3 | signature: provide error messages for unsupported function types | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
326919,5 | signature: Fix the parser regex for Qt6 | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
327163,2 | signature: Fix the parser regex for Qt6 | 6.0 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
330563,2 | signature: Provide fixes and improvements, Part 1 | 5.15 | pyside/pyside-setup | Status: ABANDONED | +1 | 0 |
330900,2 | signature: Provide fixes and improvements, Part 1 | 6.0 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
331031,3 | signature: Provide fixes and improvements, Part 1 | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
332979,3 | signature: Provide fixes and improvements, Part 1 | tqtc/lts-5.15 | pyside/tqtc-pyside-setup | Status: MERGED | +2 | 0 |
333783,2 | signature: Provide fixes and improvements, Part 1, addendum | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
333821,2 | signature: Provide fixes and improvements, Part 1, addendum | 6.0 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
333822,2 | signature: Provide fixes and improvements, Part 1, addendum | 5.15 | pyside/pyside-setup | Status: ABANDONED | -1 | 0 |
334021,2 | signature: Provide fixes and improvements, Part 1, addendum | tqtc/lts-5.15 | pyside/tqtc-pyside-setup | Status: MERGED | +2 | 0 |
425555,8 | signature: Update, cleanup and install signature test | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
427187,2 | signature: Update, cleanup and install signature test, amend | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
427204,6 | signature: Update, cleanup and install signature test | 6.3 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
427310,4 | signature: Update, cleanup and install signature test, 6.3 fix | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
438123,2 | PySide-doc: Move the signature_doc.rst into the PySide tree | 6.4 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
438124,2 | PySide-doc: Move the signature_doc.rst into the PySide tree | 6.3 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
438142,3 | PySide-doc: Move the signature_doc.rst into the PySide tree | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
442832,9 | signature: Evict the __signature__ attribute, long live signature! | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
454669,3 | shiboken: clean up a little in signature_bootstrap.py | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
454927,3 | shiboken: clean up a little in signature_bootstrap.py | 6.4 | pyside/pyside-setup | Status: MERGED | +2 | 0 |