[Python-Dev] Re: typing: how to use names in result-tuples?

2019-08-12 Thread Ivan Levkivskyi
On Mon, 12 Aug 2019 at 11:24, Christian Tismer wrote: > On 12.08.19 10:52, Ivan Levkivskyi wrote: > > On Thu, 8 Aug 2019 at 17:17, Christian Tismer > > wrote: > > > > Yes, that's what I mean. > > Probably retval or whatever people prefer would be adequate, >

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-08-12 Thread Christian Tismer
On 12.08.19 10:52, Ivan Levkivskyi wrote: > On Thu, 8 Aug 2019 at 17:17, Christian Tismer > wrote: > > Yes, that's what I mean. > Probably retval or whatever people prefer would be adequate, > with a special rule if that name is taken. > > I think

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-08-12 Thread Ivan Levkivskyi
On Thu, 8 Aug 2019 at 17:17, Christian Tismer wrote: > Yes, that's what I mean. > Probably retval or whatever people prefer would be adequate, > with a special rule if that name is taken. > > I think btw. that using StructSequence(somename=sometype, ..., ) that > does a dict lookup is quite

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-08-09 Thread Ronald Oussoren via Python-Dev
> On 8 Aug 2019, at 17:42, Christian Tismer wrote: > > On 08.08.19 17:20, Ronald Oussoren via Python-Dev wrote: >> >> >>> On 8 Aug 2019, at 17:12, Christian Tismer >> > wrote: >>> >>> Hi Ronald, >>> >>> sure, the tuple is usually not very interesting; people

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-08-08 Thread Christian Tismer
Yes, that's what I mean. Probably retval or whatever people prefer would be adequate, with a special rule if that name is taken. I think btw. that using StructSequence(somename=sometype, ..., ) that does a dict lookup is quite appealing. It returns a class like stat_result, but the function call

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-08-08 Thread Christian Tismer
On 08.08.19 17:20, Ronald Oussoren via Python-Dev wrote: > > >> On 8 Aug 2019, at 17:12, Christian Tismer > > 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

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-08-08 Thread Guido van Rossum
OK, yes, having a convention for naming the anonymous field sounds like the way to go. But presuming people will want to use it, and probably know it from the C++ API, why not name it 'return_value' or 'result' or 'retval' or something like that? On Thu, Aug 8, 2019 at 1:43 AM Christian Tismer

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-08-08 Thread Ronald Oussoren via Python-Dev
> On 8 Aug 2019, at 17:12, Christian Tismer 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

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-08-08 Thread Christian Tismer
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:

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-08-08 Thread Ronald Oussoren via Python-Dev
Chrisian, How would these namedtuple/structseq values be used? I have a similar design with PyObjC: pass-by-reference “return” values are returned in a tuple, e.g.: void getpoint(pointclass* v, int* x, int *y)=>def get point(v: pointless) -> (int, int) BOOL getvalue(someclass*

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-08-08 Thread Christian Tismer
Hi Guido, If a C++ function already has a return value, plus some primitive pointer variables that need to be moved into the result in Python, then we have the case with a first, single unnamed field. Only one such field can exist. I'm not sure if that case exists in the ~25000 Qt5 functions,

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-08-07 Thread Guido van Rossum
Alas, we didn't think of struct sequences when we designed PEP 484. It seems they are a hybrid of Tuple and NamedTuple; both of these are currently special-cased in mypy in ways that cannot easily be combined. Do you really need anonymous fields? I see an example in

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-08-07 Thread Christian Tismer
Hi all, Ok, I am about to implement generation of such structures automatically using the struct sequence concept. One more question: -- Struct sequences are not yet members of the typing types. I would like to add that, because a major use case is also to show nice .pyi files

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-07-30 Thread Christian Tismer
Hi Petr, hi Paul, the struct sequence objects are in fact interesting! About the "every instance" issue: Well, if I used something like the caching approach from Paul's post, like cached_namedtuple = lru_cache(None)(namedtuple) n1 = cached_namedtuple('f', ('a', 'b', 'c')) n2 =

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-07-30 Thread Guido van Rossum
I think I have to agree with Petr. Define explicit type names. On Tue, Jul 30, 2019 at 2:45 AM Paul Moore wrote: > On Tue, 30 Jul 2019 at 09:33, Christian Tismer > wrote: > > >>> typing.NamedTuple("__f", x=int, y=int) > > > > >>> typing.NamedTuple("__f", x=int, y=int) is

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-07-30 Thread Paul Moore
On Tue, 30 Jul 2019 at 09:33, Christian Tismer wrote: > >>> typing.NamedTuple("__f", x=int, y=int) > > >>> typing.NamedTuple("__f", x=int, y=int) is typing.NamedTuple("__f", > x=int, y=int) > False This appears to go right back to collections.namedtuple: >>> from collections import namedtuple

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-07-30 Thread Petr Viktorin
On 7/29/19 4:36 PM, Christian Tismer wrote: Hi friends, I am meanwhile the PySide maintainer at The Qt Company, and we are trying to make the mapping from Qt functions to Python functions as comparable as possible. One problem are primitive pointer variables: In Qt, it is natural to use

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-07-30 Thread Christian Tismer
Yes, maybe I can use that. With Python >= 3.6, also def f() -> typing.NamedTuple("__f", x=int, y=int): ... which is concise, but a slightly weird abuse. But there are other drawbacks: >>> typing.Tuple[int, int] typing.Tuple[int, int] >>> typing.Tuple[int, int] is typing.Tuple[int, int] True

[Python-Dev] Re: typing: how to use names in result-tuples?

2019-07-29 Thread Guido van Rossum
Can't you use the proper inline form of NamedTuple? def f() -> typing.NamedTuple("__f", [("x", int), ("y", int)]): ... seems to work. On Mon, Jul 29, 2019 at 8:26 AM Christian Tismer wrote: > Hi friends, > > I am meanwhile the PySide maintainer at The Qt Company, > and we are trying to