[PyQt] SIP 4.8: regression in div/truediv
Giovanni Bajo
rasky at develer.com
Sun Jul 26 12:22:53 BST 2009
On sab, 2009-07-25 at 17:24 +0100, Phil Thompson wrote:
> On Sat, 25 Jul 2009 03:34:38 +0200, Giovanni Bajo <rasky at develer.com>
> wrote:
> > On Fri, 24 Jul 2009 22:53:23 +0100, Phil Thompson
> > <phil at riverbankcomputing.co.uk> wrote:
> >> On Fri, 24 Jul 2009 20:43:10 +0200, Giovanni Bajo <rasky at develer.com>
> >> wrote:
> >>> Hello,
> >>>
> >>> I'm wrapping with SIP a global C++ operator/() overload, whose first
> >>> argument is a SIP-wrapped class (within the same module).
> >>>
> >>> With SIP 4.7, this function is called when I use "/" in Python, both
> >>> with standard division behaviour and within modules using "from
> >>> __future__ import division".
> >>>
> >>> With SIP 4.8, this function is called only within modules with standard
>
> >>> division behaviour. If a module uses the future directive, using "/" in
>
> >>> Python raises an exception saying that there is no valid operand types.
> >>>
> >>> I believe that the problem is that the truediv_slot of the object is
> not
> >
> >>> being filled. Is this a wanted change in behaviour? And if so, how am I
>
> >>> supposed to fix it?
> >>
> >> "/" is the same as __div__. Define __truediv__ for true division.
> >
> > I'm not sure that's a good choice for a default. "/" in Python maps to
> > __div__ in 2.x and __truediv__ in 3.x by default, but the future
> statement
> > is meant as an aid for the transition. So it's weird in SIP that simply
> > declaring something like:
> >
> > Foo operator/(Foo f, int x);
> >
> > works with Python's "/" in 2.x and 3.x, but *not* when using the
> transition
> > aid.
> >
> > I believe that "operator/" should map to both the __div__ and the
> > __truediv__ slot in Python 2.x. People that want to export a finer
> > granularity to Python (and I believe that it is highly unlikely, given
> that
> > C++ itself does not have it in the first place) could do with a
> > /ClassicDivOnly/ annotation, or by simply manually defining __div__ and
> > __truediv__ instead of using "operator/".
> >
> > Plus, it's a a change in behaviour from SIP 4.7 :)
>
> Actually "operator/" is completely broken for Python v3. Should all be
> fixed in tonight's snapshot - with the 4.7 behavior for Python v2.
Thanks. I noticed that the snapshot contains parser.c generated with
Bison 1.875d instead of Bison 2.3 (used in SIP 4.8.1). Is this a mistake
or you really downgraded the Bison version you use for SIP?
--
Giovanni Bajo
Develer S.r.l.
http://www.develer.com
More information about the PyQt
mailing list