On 8 Aug 2019, at 17:42, Christian Tismer <tismer@stackless.com> wrote:
On 08.08.19 17:20, Ronald Oussoren via Python-Dev wrote:
On 8 Aug 2019, at 17:12, Christian Tismer <tismer@stackless.com <mailto:tismer@stackless.com>> wrote:
Hi Ronald,
sure, the tuple is usually not very interesting; people look it up once and use that info in the code.
But I think things can be made quite efficient and pretty at the same time. Such a return tuple could be hidden like the stat_result example that Guido mentioned:
https://github.com/python/typeshed/blob/master/stdlib/3/os/__init__.pyi
def stat(self, *, follow_symlinks: bool = ...) -> stat_result: ...
The stat_result is a huge structure where you don't want to see much unless you are working with a stat_result.
Other with common, repeating patterns like (x, y, width, height) or your examples:
def getpoint(v: pointless) -> (int, int) def getvalue(v: someclass) -> (bool, int)
would be at first sight
def getpoint(v: pointless) -> getpoint_result def getvalue(v: someclass) -> getvalue_result
But actually, a much nicer, speaking outcome would be written as the single function StructSequence(...) with arguments, producing:
def getpoint(v: pointless) -> StructSequence(x=int, y=int) def getvalue(v: someclass) -> StructSequence(result=bool, val=int)
That would have the nice effect of a very visible structure in the .pyi file. When you actually get such an object and look at it, then you have
But will you ever look at these objects, other then when exploring APIs in the REPL? As I wrote earlier the normal usage for a similar pattern in PyObjC is to always immediately deconstruct the tuple into its separate values.
Yes, it is for exploring the interface. In Qt5, you have *very* many functions, and they are pretty unpythonic as well.
You haven’t seen the interfaces generated by PyObjC, compared to the PyQt interfaces are pretty pythonic :-).
That was the reason at all for me to write that __signature__ module for PySide, that does everything with introspection.
When I'm programming with it, then half as a user who wants to see "yes, it really returns such a value" and as a developer "shit, we claim that interface, but lied".
In a sense, it was also a way to test this huge library automatically, and I enjoy it when things can explain themselves. That is absolutely not necessary.
As the whole typing idea and typeshed is not necessary, but for me it was a huge win to have a typed interface, and IDE users seem to love it when PyCharm suddenly talks to them ;-)
I like the idea, even if it is just used for introspection and interactive use. I’m definitely adding exploring this for PyObjC to my list. Ronald — Twitter: @ronaldoussoren Blog: https://blog.ronaldoussoren.net/