__signature__ for PySide ready

Hi friends, in the last months, I have developed signature support for PySide. The module creates the same signatures as are known for plain Python functions. As a non-trivial addition, the module also handles multiple signatures as a list. I consider this extension to PySide as quite essential and actually more important as for Python itself, because type info is rather crucial for PySide. Initially, I wrote this as a pure Python 3 extension. Then I was "asked" to port this to Python 2 too, which was quite hairy to do. I'm not sure if I should have done that. Before I publish this module, I want to ask: -------------------------------------------- Is it a bad idea to support signatures in Python 2 as well? Do I introduce a feature that should not exist in Python 2? Or is it fine to do so? Please let me know your opinion, I am happy with any result. Cheers -- Chris -- Christian Tismer :^) tismer@stackless.com Software Consulting : http://www.stackless.com/ Karl-Liebknecht-Str. 121 : https://github.com/PySide 14482 Potsdam : GPG key -> 0xFB7BEE0E phone +49 173 24 18 776 fax +49 (30) 700143-0023

Hi Christian, On Fri, Aug 18, 2017 at 4:41 AM, Christian Tismer <tismer@stackless.com> wrote:
Hi friends,
in the last months, I have developed signature support for PySide. The module creates the same signatures as are known for plain Python functions.
As a non-trivial addition, the module also handles multiple signatures as a list. I consider this extension to PySide as quite essential and actually more important as for Python itself, because type info is rather crucial for PySide.
Initially, I wrote this as a pure Python 3 extension. Then I was "asked" to port this to Python 2 too, which was quite hairy to do. I'm not sure if I should have done that.
Before I publish this module, I want to ask: --------------------------------------------
Is it a bad idea to support signatures in Python 2 as well?
There's a backport of signature API to Python 2. Although last time I checked it was fairly outdated.
Do I introduce a feature that should not exist in Python 2? Or is it fine to do so?
Please let me know your opinion, I am happy with any result.

2017-08-18 18:20 GMT+02:00 Yury Selivanov <yselivanov.ml@gmail.com>:
Hi Christian,
On Fri, Aug 18, 2017 at 4:41 AM, Christian Tismer <tismer@stackless.com> wrote:
Hi friends,
in the last months, I have developed signature support for PySide. The module creates the same signatures as are known for plain Python functions.
As a non-trivial addition, the module also handles multiple signatures as a list. I consider this extension to PySide as quite essential and actually more important as for Python itself, because type info is rather crucial for PySide.
Initially, I wrote this as a pure Python 3 extension. Then I was "asked" to port this to Python 2 too, which was quite hairy to do. I'm not sure if I should have done that.
Before I publish this module, I want to ask: --------------------------------------------
Is it a bad idea to support signatures in Python 2 as well?
There's a backport of signature API to Python 2. Although last time I checked it was fairly outdated.
I wrote a backport earlier this year: https://pypi.python.org/pypi/inspect2.
Do I introduce a feature that should not exist in Python 2? Or is it fine to do so?
Please let me know your opinion, I am happy with any result.
Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/ jelle.zijlstra%40gmail.com

On 19 August 2017 at 02:55, Jelle Zijlstra <jelle.zijlstra@gmail.com> wrote:
2017-08-18 18:20 GMT+02:00 Yury Selivanov <yselivanov.ml@gmail.com>:
There's a backport of signature API to Python 2. Although last time I checked it was fairly outdated.
I wrote a backport earlier this year: https://pypi.python.org/pypi/inspect2.
Nice. Yury was probably referring to https://funcsigs.readthedocs.io/, which is a partial backport specifically of inspect.Signature and friends. Either way, the answer to Christian's original question is that "Yes, supporting __signature__ is also useful in Python 2.x", as even though the native inspect module doesn't support it, 3rd party backports do. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

Hi Nick, On 19.08.17 09:37, Nick Coghlan wrote:
On 19 August 2017 at 02:55, Jelle Zijlstra <jelle.zijlstra@gmail.com> wrote:
2017-08-18 18:20 GMT+02:00 Yury Selivanov <yselivanov.ml@gmail.com>:
There's a backport of signature API to Python 2. Although last time I checked it was fairly outdated.
I wrote a backport earlier this year: https://pypi.python.org/pypi/inspect2.
Nice.
Yury was probably referring to https://funcsigs.readthedocs.io/, which is a partial backport specifically of inspect.Signature and friends.
Either way, the answer to Christian's original question is that "Yes, supporting __signature__ is also useful in Python 2.x", as even though the native inspect module doesn't support it, 3rd party backports do.
I did not use a backport, but simply hacked it together, myself: - Take the signature part of Python 3.6 out, - Adjust the syntax to Python 2.7. The hairy part was my way to create the PySide PyCFunction objects in a compatible way like Python 3 does it: the handling of PyCFunction's "self" parameter is different (holds type info, Python 2 does not). That needed much more internal knowledge as intended... Well, I thought the existence of __signature__ might be a good reason to switch to Python 3, but if I support Python 2, the advantage is gone. But if it's ok with you, then I'll publish both versions. Thanks a lot for the feedback. Ciao - Chris -- Christian Tismer :^) tismer@stackless.com Software Consulting : http://www.stackless.com/ Karl-Liebknecht-Str. 121 : https://github.com/PySide 14482 Potsdam : GPG key -> 0xFB7BEE0E phone +49 173 24 18 776 fax +49 (30) 700143-0023

On 19 August 2017 at 18:38, Christian Tismer <tismer@stackless.com> wrote:
On 19.08.17 09:37, Nick Coghlan wrote:
Either way, the answer to Christian's original question is that "Yes, supporting __signature__ is also useful in Python 2.x", as even though the native inspect module doesn't support it, 3rd party backports do.
I did not use a backport, but simply hacked it together, myself:
- Take the signature part of Python 3.6 out, - Adjust the syntax to Python 2.7.
The backports we're talking about are the ones that can *read* __signature__ attributes, as well as synthesise them from the underlying attributes on Python level functions and code objects.
The hairy part was my way to create the PySide PyCFunction objects in a compatible way like Python 3 does it: the handling of PyCFunction's "self" parameter is different (holds type info, Python 2 does not). That needed much more internal knowledge as intended...
Well, I thought the existence of __signature__ might be a good reason to switch to Python 3, but if I support Python 2, the advantage is gone. But if it's ok with you, then I'll publish both versions.
The builtins and standard library extension modules in 2.7 will never gain signature information (since there's no equivalent of Argument Clinic to populate the __text_signature__ attributes). However, aside from it being extra work that they may not want to do, there's no particular reason for 3rd party modules to avoid providing better signatures in Python 2.x. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

On Fri, 18 Aug 2017 at 02:05 Christian Tismer <tismer@stackless.com> wrote:
Hi friends,
in the last months, I have developed signature support for PySide. The module creates the same signatures as are known for plain Python functions.
As a non-trivial addition, the module also handles multiple signatures as a list. I consider this extension to PySide as quite essential and actually more important as for Python itself, because type info is rather crucial for PySide.
Initially, I wrote this as a pure Python 3 extension. Then I was "asked" to port this to Python 2 too, which was quite hairy to do. I'm not sure if I should have done that.
Before I publish this module, I want to ask: --------------------------------------------
Is it a bad idea to support signatures in Python 2 as well? Do I introduce a feature that should not exist in Python 2? Or is it fine to do so?
Please let me know your opinion, I am happy with any result.
If you're getting paid to do the port then I don't think it really hurts anything since it isn't going to magically open Python 2 to more usage. In fact, if you are filling in the annotation information so that type hints are being exposed then maybe there's a chance it might help someone port to Python 3?

Hi Brett, On 18.08.17 18:31, Brett Cannon wrote:
On Fri, 18 Aug 2017 at 02:05 Christian Tismer <tismer@stackless.com <mailto:tismer@stackless.com>> wrote:
...
Is it a bad idea to support signatures in Python 2 as well? Do I introduce a feature that should not exist in Python 2? Or is it fine to do so?
Please let me know your opinion, I am happy with any result.
If you're getting paid to do the port then I don't think it really hurts anything since it isn't going to magically open Python 2 to more usage. In fact, if you are filling in the annotation information so that type hints are being exposed then maybe there's a chance it might help someone port to Python 3?
Well, I took extra precautions to make sure that existing PyCFunctions are not affected in any way. The new types are clones of the original types, and only PySide sees the additional attribute for it's functions. So, no, I don not create magically signatures for Python 2 functions. But I really warned my customer that the feature might not be welcomed for Python 2, and we might only enable it internally for testing. As said, I'm happy with either answer. Cheers -- Chris -- Christian Tismer :^) tismer@stackless.com Software Consulting : http://www.stackless.com/ Karl-Liebknecht-Str. 121 : https://github.com/PySide 14482 Potsdam : GPG key -> 0xFB7BEE0E phone +49 173 24 18 776 fax +49 (30) 700143-0023
participants (5)
-
Brett Cannon
-
Christian Tismer
-
Jelle Zijlstra
-
Nick Coghlan
-
Yury Selivanov