[PyQt] Type annotations for QStrings: str or Optional[str]?

Florian Bruhin me at the-compiler.org
Mon Nov 26 20:41:53 GMT 2018


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?

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).

Florian

-- 
https://www.qutebrowser.org | me at 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/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20181126/ae5e8260/attachment.sig>


More information about the PyQt mailing list