On Wed, Apr 27, 2022 at 03:58:22PM +0100, Phil Thompson wrote:
>> On 26/04/2022 20:49, Florian Bruhin wrote:
> > On Tue, Apr 26, 2022 at 09:36:25PM +0200, Florian Bruhin wrote:
> > > On Tue, Apr 26, 2022 at 09:19:05AM +0100, Phil Thompson wrote:
> > > >
> > > > On 21/04/2022 10:37, Florian Bruhin wrote:
> > > > > Hey,
> > > > >
> > > > > With PyQt5:
> > > > >
> > > > > >>> evtype = QEvent(QEvent.Type.User).type()
> > > > > >>> evtype
> > > > > 1000
> > > > > >>> type(evtype)
> > > > > <class 'PyQt5.QtCore.QEvent.Type'>
> > > > >
> > > > > and even:
> > > > >
> > > > > >>> evtype = QEvent(QEvent.Type.User + 1).type()
> > > > > >>> evtype
> > > > > 1001
> > > > > >>> type(evtype)
> > > > > <class 'PyQt5.QtCore.QEvent.Type'>
> > > > >
> > > > > but with PyQt6, the type information gets lost:
> > > > >
> > > > > >>> evtype = QEvent(QEvent.Type.User).type()
> > > > > >>> evtype
> > > > > 1000
> > > > > >>> type(evtype)
> > > > > <class 'int'>
> > > > >
> > > > > From what I understand, it's not possible to convert arbitrary values
> > > > > into an IntEnum:
> > > > >
> > > > > >>> QEvent.Type(QEvent.Type.User + 1)
> > > > > [...]
> > > > > ValueError: 1001 is not a valid QEvent.Type
> > > > >
> > > > > But least for types which are part of QEvent.Type, calling .type()
> > > > > should perhaps return the IntEnum value again instead of falling back to
> > > > > an int without any type information? Given that IntEnum is an int
> > > > > subclass, this should be a backwards-compatible change too.
> > > >
> > > > I've been adopting a piecemeal approach to this sort of thing so far. For
> > > > example having QEvent.type() return an int and adding an extra QEvent ctor
> > > > that accepts an int, and similar with gesture types. However the issue you
> > > > point out in your other email (new enum members in later versions of Qt) is
> > > > something I hadn't considered.
> > > >
> > > > I think the solution is to take the approach you suggest above and apply it
> > > > to all enums (no matter what their base type is). In other words, when
> > > > converting from Python to a C++ enum both a Python enum and an int will be
> > > > accepted. When converting from a C++ enum to Python then the corresponding
> > > > enum member will be returned or an int if there is no such member.
> > > >
> > > > This would mean that there is no need for me to apply special treatment to
> > > > individual methods (as the change is implemented in the sip module) and the
> > > > approach should be future-proof.
> > > >
> > > > Thoughts?
> > >
> > > Hm, I don't really like the lost type safety when accepting ints.
> > > However, at the same time I can't think of a proper way to solve the
> > > "new enum members" problem.
> > >
> > > I tried coercing Python into having some kind of special
> > > SomeEnum.missing(42) value instead, which acts like a member of the
> > > enum, but can also hold an arbitrary value. enum.py sure is some crazy
> > > black magic. I bet it would be possible somehow (custom enum metaclass
> > > defining __instancecheck__ perhaps?), but at this point there is so
> > > much
> > > black magic involved I'm not sure it would be a better solution.
> >
> > I spoke too soon, here is something that seems to work, somehow.
> > The point about "probably too much black magic" still stands, though.
>> Nice. The obvious problem is the knowledge of the enum internals.
Right. The code still works properly when removing the setting of
_value2member_map_, though. I was copying this from a similar suggestion
using _missing_ initially: https://stackoverflow.com/a/57179436
There, it's only needed so that calling CustomEnum(3) later returns the
same object again. I believe this isn't needed in PyQt's case, and
actually it doesn't work properly either (since we're not using
_missing_).
Is it strange that the user gets an enum value back, for which the
invariant SomePyQtEnum(member.value) == member does not hold true?
I don't believe it really is, given that the PyQt enum really doesn't
know what member the value corresponds to after all.
One thing that might require some extra care is making the values
pickleable I suppose:
>>> pickle.loads(pickle.dumps(SomePyQtEnum._from_qt(3)))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.10/enum.py", line 385, in __call__
return cls.__new__(cls, value)
File "/usr/lib/python3.10/enum.py", line 710, in __new__
raise ve_exc
ValueError: 3 is not a valid SomePyQtEnum
I know nothing about pickle, but if you're still interested in this
approach, I can try to make it work too.
> I'm still favouring the int approach. I can't think of a case that code
> would start to break when a newer version of Qt was used with an older PyQt
> (which is the main problem).
My main gripe with that approach is that it allows it to pass ints
instead of enum members again (even corresponding to a different enum,
of course).
If you'd prefer not messing with the enums directly, I'd prefer an
approach which at least tries to be type-safe to some degree, e.g. via a
sip.UnknownEnumMember(QEvent.Type, 1001) or somesuch.
That way:
- ints can't be accidentally passed where enum members are expected
- Passing a sip.UnknownEnumMember belonging to a different enum would
still raise a TypeError of some sorts.
- In summary, whatever I get out of PyQt I can only pass into PyQt at
the correct place again, which seems like a great thing.
- Type checkers could probably made to understand it statically
(I think?).
- From the __repr__, it would still be clear what kind of thing I'm
dealing with, rather than just seeing 1001 and having no idea where it
comes from.
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: </pipermail/pyqt/attachments/20220427/946b5533/attachment.sig>
More information about the PyQt
mailing list
‘She has never mentioned her father to me. Was he—well, the sort of man whom the County Club would not have blackballed?’ "We walked by the side of our teams or behind the wagons, we slept on the ground at night, we did our own cooking, we washed our knives by sticking them into the ground rapidly a few times, and we washed our plates with sand and wisps of grass. When we stopped, we arranged our wagons in a circle, and thus formed a 'corral,' or yard, where we drove our oxen to yoke them up. And the corral was often very useful as a fort, or camp, for defending ourselves against the Indians. Do you see that little hollow down there?" he asked, pointing to a depression in the ground a short distance to the right of the train. "Well, in that hollow our wagon-train was kept three days and nights by the Indians. Three days and nights they stayed around, and made several attacks. Two of our men were killed and three were wounded by their arrows, and others had narrow escapes. One arrow hit me on the throat, but I was saved by the knot of my neckerchief, and the point only tore the skin a little. Since that time I have always had a fondness for large neckties. I don't know how many of the Indians we killed, as they carried off their dead and wounded, to save them from being scalped. Next to getting the scalps of their enemies, the most important thing with the Indians is to save their own. We had several fights during our journey, but that one was the worst. Once a little party of us were surrounded in a small 'wallow,' and had a tough time to defend ourselves successfully. Luckily for us, the Indians had no fire-arms then, and their bows and arrows were no match for our rifles. Nowadays they are well armed, but there are[Pg 41] not so many of them, and they are not inclined to trouble the railway trains. They used to do a great deal of mischief in the old times, and many a poor fellow has been killed by them." As dusk came on nearly the whole population of Maastricht, with all their temporary guests, formed an endless procession and went to invoke God's mercy by the Virgin Mary's intercession. They went to Our Lady's Church, in which stands the miraculous statue of Sancta Maria Stella Maris. The procession filled all the principal streets and squares of the town. I took my stand at the corner of the Vrijthof, where all marched past me, men, women, and children, all praying aloud, with loud voices beseeching: "Our Lady, Star of the Sea, pray for us ... pray for us ... pray for us ...!" It had not occurred to her for some hours after Mrs. Campbell had told her of Landor's death that she was free now to give herself to Cairness. She had gasped, indeed, when she did remember it, and had put the thought away, angrily and self-reproachfully. But it returned now, and she felt that she might cling to it. She had been grateful, and she had been faithful, too.[Pg 286] She remembered only that Landor had been kind to her, and forgot that for the last two years she had borne with much harsh coldness, and with a sort of contempt which she felt in her unanalyzing mind to have been entirely unmerited. Gradually she raised herself until she sat quite erect by the side of the mound, the old exultation of her half-wild girlhood shining in her face as she planned the future, which only a few minutes before had seemed so hopeless. After he had gloated over Sergeant Ramsey, Shorty got his men into the road ready to start. Si placed himself in front of the squad and deliberately loaded his musket in their sight. Shorty took his place in the rear, and gave out: The groups about each gun thinned out, as the shrieking fragments of shell mowed down man after man, but the rapidity of the fire did not slacken in the least. One of the Lieutenants turned and motioned with his saber to the riders seated on their horses in the line of limbers under the cover of the slope. One rider sprang from each team and ran up to take the place of men who had fallen. "As long as there's men and women in the world, the men 'ull be top and the women bottom." Then, in the house, the little girls were useful. Mrs. Backfield was not so energetic as she used to be. She had never been a robust woman, and though her husband's care had kept her well and strong, her frame was not equal to Reuben's demands; after fourteen years' hard labour, she suffered from rheumatism, which though seldom acute, was inclined to make her stiff and slow. It was here that Caro and Tilly came in, and Reuben began to appreciate his girls. After all, girls were needed in a house—and as for young men and marriage, their father could easily see that such follies did not spoil their usefulness or take them from him. Caro and Tilly helped their grandmother in all sorts of ways—they dusted, they watched pots, they shelled peas and peeled potatoes, they darned house-linen, they could even make a bed between them. HoME一级毛片视频免费公开
ENTER NUMBET 0018www.astartup.com.cn www.cottonhouse.net.cn www.shehua55.net.cn www.moliaoapp.com.cn www.xipys.com.cn www.gvgi.com.cn shagege.com.cn hihop.com.cn ustoreai.com.cn aksar.com.cn