typing: Add argument type for *args

Phil Thompson phil at riverbankcomputing.com
Sat Jul 15 21:55:27 BST 2023


On 14/07/2023 16:30, Florian Bruhin wrote:
>> 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/

Fixed.

Thanks,
Phil


More information about the PyQt mailing list