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 <tis...@stackless.com> 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 "sometype *varname" to make a > mutable variable. In Python, you have to turn such a thing > into a result-tuple. Example: > > void QPrinter::getPageMargins(qreal *left, qreal *top, \ > qreal *right, qreal *bottom, QPrinter::Unit unit) const > > (meanwhile deprecated, but a good example) > > is mapped to the Python signature > > def getPageMargins(self, \ > unit: PySide2.QtPrintSupport.QPrinter.Unit) \ > -> typing.Tuple[float, float, float, float]: ... > > NOW my question: > ---------------- > > I would like to retain the variable names in Python! > The first idea is to use typing.NamedTuple, but I get the impression > that this would be too much, because I would not only need to create > an extra named tuple definition for every set of names, but also > invent a name for that named tuple. > > What I would like to have is something that looks like > > def getPageMargins(self, \ > unit: PySide2.QtPrintSupport.QPrinter.Unit) \ > -> typing.NamedTuple[left: float, top: float, \ > right:float, bottom:float]: ... > > but that is obviously not a named tuple. > Possible would be to derive a name from the function, so maybe > a definition could be used like > > class PageMargingResult(NamedTuple): > left: float > top: float > right: float > bottom: float > > but then I would have some opaque PageMargingResult type. This would > work, but as said, this is a bit too much, since I only > wanted something like a tuple with names. > > What do you suggest to do here? Something what I am missing? > > Cheers -- 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/YGZELVWRGXZ5BTD4ZMATQT7IRAZVQSHR/ > -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him/his **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________ 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/LSNP3DUXGP3SD3BVMSWROAGPC67T26XE/