C extension type gives type error in power operator
Paul Moore
p.f.moore at gmail.com
Thu Nov 20 10:57:21 EST 2008
On 20 Nov, 15:43, Thomas Heller <thel... at python.net> wrote:
> Paul Moore schrieb:
> > However, when I try to use the operator, I get the following
> > error:
> > TypeError: unsupported operand type(s) for ** or pow():
> > '_ppeg.Pattern' and 'int'
>
> Try to set Py_TPFLAGS_CHECKTYPES in your extension type (in the
> tp_flags slot).
>
> from object.h:
> /* PyNumberMethods do their own coercion */
> #define Py_TPFLAGS_CHECKTYPES (1L<<4)
Excellent! That did exactly what I wanted. (I wonder how it affects my
other operations - I'll look into that, it probably helps in ways I
hadn't suspected).
> > Oh, and is there a good reference for writing C extensions for
> > Python anywhere? The manuals aren't bad, but I keep hitting
> > empty sections (e.g., 10.5 Number Object Structures).
>
> I normally look into the newest python reference manual, even if
> I'm programming for older versions. But sometimes you have to
> took into the header files, too.
This particular issue was in the 2.6 manual. I hadn't thought to check
there. Add "browse the 2.6 manuals" to my ever-increasing todo
list :-) Or maybe just get round to installing 2.6, and be done with
it.
Or there's always ask the experts on clp :-) (I did at least look in
the sources, but never thought of checking the type flags).
Thanks,
Paul
More information about the Python-list
mailing list