.api/.pyi files and scoped enums
Kovid Goyal
kovid at kovidgoyal.net
Sun Dec 6 03:55:20 GMT 2020
In my opinion, having PyQt6 disallow access to enums at the top level
is a mistake. FOr the following reasons:
1) It adds a huge maintenance burden to move from PyQt5 to
PyQt6, and Florian's valiant efforts nothwithstanding, this cant be done
automatically. Remember that enum values can be accessed from instances
as well as classes. For instance the following idiom is very common in
calibre code:
d = SomeQDialogDerivedClass()
if d.exec_() == d.Accepted: # to avoid having to type SomeQDialogDerivedClass
...
2) Accessing enum values via scope is a huge and largely unnecessary
pain. You have to type redundant information every time.
Qt.GlobalColor.white is just stupid compared to Qt.white. Not to mention
that the extra attribute access is a performance cost, albeit a tiny
one.
I strongly suggest that you preserve the existing top level enums in
PyQt6. By all means use scoped ones for new enums and change the docs to
encourage people to use scoped ones if you prefer. But breaking backward
compatibility like this is really not a good idea. It would be one thing
if these could be migrated reliably automatically, but they cant. So its
going to create huge amounts of unneccessary and very boring make work
and there will be some that inevitably slip through the cracks causing
runtime errors for end users.
On Tue, Dec 01, 2020 at 05:57:12PM +0000, Phil Thompson wrote:
> On 01/12/2020 17:51, Florian Bruhin wrote:
> > Hey,
> >
> > After trying to find out if I can automatically rewrite enums for scoped
> > access, I looked at the .api output (since the XML export doesn't seem
> > to exist anymore?).
> >
> > However, I noticed that the generated files still contain the unscoped
> > names, e.g. "QtCore.Qt.NoButton?10" rather than
> > "QtCore.Qt.MouseButton.NoButton?10".
> >
> > Something similar applies to the .pyi files, which contain:
> >
> > class MouseButton(int): ...
> > NoButton = ... # type: 'Qt.MouseButton'
> >
> > (note that the members are not part of the class scope, they are
> > directly in the enclosing "Qt" class)
> >
> > That's with:
> >
> > PyQt-builder==1.6.0
> > PyQt5==5.15.2
> > PyQt5-sip==12.8.1
> > sip==5.5.0
> >
> > Is this intended?
>
> No, just haven't got round to everything yet.
>
> Phil
>
--
_____________________________________
Dr. Kovid Goyal
https://www.kovidgoyal.net
https://calibre-ebook.com
_____________________________________
More information about the PyQt
mailing list