[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: Type hints: Operators declared outside class
From:       Phil Thompson <phil () riverbankcomputing ! com>
Date:       2023-07-12 11:11:17
Message-ID: fcca95796b2d1efbb49c49edef6c54b4 () riverbankcomputing ! com
[Download RAW message or body]

On 08/07/2023 23:38, Florian Bruhin wrote:
> Hey,
> 
> If an operator is designed outside a class, such as e.g. in
> QtCore/qsize.sip:
> 
>     QSize operator+(const QSize &s1, const QSize &s2);
> 
> in the type annotations, this turns into:
> 
>     def __add__(self, s1: 'QSize', s2: 'QSize') -> 'QSize': ...
> 
> which is however incorrect, and results in e.g.:
> 
>     from PyQt6.QtCore import QSize
>     print(QSize(1, 2) + QSize(3, 4))
> 
> to be flagged as wrong with:
> 
>     error: Too few arguments for "__add__" of "QSize"  [call-arg]
> 
> This seems to be an issue with almost all operators on various 
> different
> classes.
> 
> Note that it's not necessarly always the first argument, e.g. in 
> QMargin
> there is:
> 
>     @typing.overload
>     def __add__(self, lhs: 'QMargins', rhs: int) -> 'QMargins': ...
>     @typing.overload
>     def __add__(self, lhs: int, rhs: 'QMargins') -> 'QMargins': ...
> 
> where the second one should probably just be dropped.
> 
> Florian

Fixed in the next SIP snapshot.

Thanks,
Phil
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic