PyQt6: QEvent.type() returns int instead of QEvent.Type
Florian Bruhin
me at the-compiler.org
Fri Apr 29 13:50:16 BST 2022
On Thu, Apr 28, 2022 at 09:16:33PM +0200, Florian Bruhin wrote:
> > See the attached. This has an acceptably minimal knowledge of enum
> > internals. Note that I have adopted the Flags naming convention for
> > pseudo-members, but I'm not sure wether this is Ok for negative values.
>
> I think there is no inherent limitation of what can be in a Python name.
> The only limitations are syntactic, but e.g. this works:
>
> >>> class T(): pass
> ...
> >>> t = T()
> >>> setattr(t, "-1 hello world", True)
> >>> getattr(t, "-1 hello world")
> True
>
> and the functional enum API doesn't hold you back either:
>
> >>> E = enum.Enum("E", "-1")
> >>> list(E)
> [<E.-1: 1>]
>
> so I suppose it won't be a problem.
>
> I'd still prefer something like f"sip_unknown_{cpp}" or so, though:
> Still shouldn't conflict with real enum values, but it at least
> generates valid identifiers for positive values, and it makes it a bit
> clearer to the user what's going on.
I hadn't noticed earlier, but the name for unknown IntFlags generated by
Python is actually set to None, it's just the __repr__ which shows the
value as pseudo-name:
>>> from PyQt6.QtCore import Qt
>>> Qt.AlignmentFlag(1024)
<AlignmentFlag.1024: 1024>
>>> Qt.AlignmentFlag(1024).name
>>>
Florian
--
me at the-compiler.org | https://www.qutebrowser.org
https://bruhin.software/ | https://github.com/sponsors/The-Compiler/
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/20220429/b8be1231/attachment.sig>
More information about the PyQt
mailing list