typing: Add argument type for *args

Florian Bruhin me at the-compiler.org
Fri Jul 14 16:30:38 BST 2023


> On 09/07/2023 01:11, Florian Bruhin wrote:
> > There are some places in PyQt where it takes *args, namely:
> > 
> >     [...]
> > 
> > Unfortunately, this results in "*a1" or "*a2" in the .pyi, without any
> > type information.
> > 
> > From what I can see in PyQt6-stubs, those should be:
> > 
> > - int for QPolygon
> > - The same type as the first argument for QPainter
> > - Any for QDBusAbstractInterface
> >   (an explicit "Any" would be preferrable to no annotation)
> 
> Don't those imply a single argument? How do you express 'any number of 
> int arguments'?

`*args: int` is defined as "any number of int arguments", see e.g. the
last example here:
https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#functions

Or in the original typing pep:
https://peps.python.org/pep-0484/#arbitrary-argument-lists-and-default-argument-values

What's not possible AFAIK is to annotate a *args where the types differ
between elements. For **kwargs, it recently became possible with
TypedDict and typing.Unpack: https://peps.python.org/pep-0692/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20230714/f9917703/attachment.sig>


More information about the PyQt mailing list