On 08.08.19 17:20, Ronald Oussoren via Python-Dev wrote: > > >> On 8 Aug 2019, at 17:12, Christian Tismer <tis...@stackless.com >> <mailto:tis...@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. 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 ;-) > BTW. I’m primarily trying to understand your use case because it is so > similar to what I’m doing in PyObjC, and such understanding can lead to > an improvement in PyObjC ;-). I am happy to learn from your projects as well! All the best -- Chris -- Christian Tismer :^) tis...@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 _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/TUQVQIRTBSI6HCWBRKAZTCCTNVKCLXJJ/