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

List:       pykde
Subject:    Re: [PyQt] Type annotations for QStrings: str or Optional[str]?
From:       Florian Bruhin <me () the-compiler ! org>
Date:       2018-11-27 9:59:53
Message-ID: 20181127095953.yvutg7tcwzgnqueg () hooch ! localdomain
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


On Mon, Nov 26, 2018 at 09:57:32PM +0000, Phil Thompson wrote:
> On 26 Nov 2018, at 8:41 pm, Florian Bruhin <me@the-compiler.org> wrote:
> > 
> > Hi,
> > 
> > sip/QtCore/qstring.sip says:
> > 
> >  %MappedType QString /AllowNone,TypeHint="str",TypeHintValue="''"/
> > 
> > At least where Qt functions take a QString as argument, passing None
> > should always be allowed, so I think Optional[str] would be more
> > appropriate?
> 
> More accurate, yes..
> 
> > Where they return a QString, I'm not so sure - what happens if Qt
> > returns a null QString? Even if PyQt maps that to None, it seems rather
> > cumbersome to have Optional[str] there, as that'd mean you'd need to
> > check every QString return value for None-ness (which isn't really done
> > in practice, as often you wouldn't expect to ever get None back).
> 
> Both null and empty QStrings are converted to ''.
> 
> IMHO 'str' rather than 'Optional[str]' is less clunky, particularly in
> docstrings. I'm not sure null QStrings are even still used.

Fair point. FWIW, in my codebase it turned up with
QApplication::setOrganizationName() and QFileDialog::getOpenFileNames
(its "caption" argument). From a quick look at Qt's sources, it seems to
check for .isEmpty() in both cases, so I suppose I could just use ""
there instead.

Florian

-- 
https://www.qutebrowser.org | me@the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
         I love long mails! | https://email.is-not-s.ms/

["signature.asc" (application/pgp-signature)]
[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt


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

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