[Pyrex] Inheritance for extension types: the sequel
Alain Pointdexter
alainpoint at yahoo.fr
Mon Feb 16 10:37:16 CET 2004
Dear all
I first want to thank you all for your help. Using
'__init__' instead of '__new__' does indeed resolve
the problem.
I would however suggest to improve the doc as it gives
the impression that '__new__' is the way to do it.
I also apologize for not being accurate enough. The
example given in my previous post did not work but did
compile.
In a nutshell, pyrex fails when the derived and base
classes are defined in separate files.
The example which does not compile is as follows:
I have four files:
a.pxd and a.pyx for the base class
and
b.pxd and b.pyx for the derived class
with the respective following contents:
# a.pxd
cdef class A:
cdef int length
#a.pyx
cdef class A:
def __init__(self,length):
self.length=length
#b.pxd
cimport a
cdef class B(a.A):
cdef int width
#b.pyx
cimport a
cdef class B(a.A):
def __init__(self,length,width):
a.A.__init__(self,length)
self.width=width
I get the following traceback:
---------- pyrex make ----------
MAKE Version 5.2 Copyright (c) 1987, 2000 Borland
python Setup.py build_ext --inplace --compiler=bcpp
running build_ext
building 'a' extension
creating build
creating build\temp.win32-2.3
creating build\temp.win32-2.3\Release
C:\Borland\Bcc55\bin\bcc32.exe -c /tWM /O2 /q /g0
-IC:\Python23\include -IC:\Python23\PC
-obuild\temp.win32-2.3\Release\a.obj a.c
a.c:
Warning W8004 a.c 75: 'p' is assigned a value that is
never used in function __pyx_tp_new_1a_A
Warning W8057 a.c 75: Parameter 'a' is never used in
function __pyx_tp_new_1a_A
Warning W8057 a.c 75: Parameter 'k' is never used in
function __pyx_tp_new_1a_A
Warning W8004 a.c 80: 'p' is assigned a value that is
never used in function __pyx_tp_dealloc_1a_A
Warning W8004 a.c 86: 'p' is assigned a value that is
never used in function __pyx_tp_traverse_1a_A
Warning W8057 a.c 86: Parameter 'v' is never used in
function __pyx_tp_traverse_1a_A
Warning W8057 a.c 86: Parameter 'a' is never used in
function __pyx_tp_traverse_1a_A
Warning W8004 a.c 91: 'p' is assigned a value that is
never used in function __pyx_tp_clear_1a_A
Warning W8004 a.c 246: 'py_globals' is assigned a
value that is never used in function
__Pyx_AddTraceback
Warning W8004 a.c 244: 'py_srcfile' is assigned a
value that is never used in function
__Pyx_AddTraceback
writing build\temp.win32-2.3\Release\a.def
C:\Borland\Bcc55\bin\ilink32.exe /Tpd /Gn /q /x
/LC:\Python23\libs /LC:\Python23\PCBuild /L. c0d32
build\temp.win32-2.3\Release\a.obj , a.pyd ,,
C:\Python23\libs\python23_bcpp.lib import32 cw32mt ,
build\temp.win32-2.3\Release\a.def ,
building 'b' extension
Traceback (most recent call last):
File "Setup.py", line 11, in ?
cmdclass = {'build_ext': build_ext}
File "C:\Python23\lib\distutils\core.py", line 149,
in setup
dist.run_commands()
File "C:\Python23\lib\distutils\dist.py", line 907,
in run_commands
self.run_command(cmd)
File "C:\Python23\lib\distutils\dist.py", line 927,
in run_command
cmd_obj.run()
File
"C:\Python23\lib\distutils\command\build_ext.py", line
269, in run
self.build_extensions()
File
"C:\Python23\lib\distutils\command\build_ext.py", line
395, in build_extensions
self.build_extension(ext)
File
"C:\Python23\lib\distutils\command\build_ext.py", line
432, in build_extension
sources = self.swig_sources(sources)
File
"C:\Python23\Lib\site-packages\Pyrex\Distutils\build_ext.py",
line 52, in swig_sources
self.pyrex_compile(source)
File
"C:\Python23\Lib\site-packages\Pyrex\Distutils\build_ext.py",
line 66, in pyrex_compile
result = Pyrex.Compiler.Main.compile(source,
c_only=1)
File
"C:\Python23\Lib\site-packages\Pyrex\Compiler\Main.py",
line 238, in compile
return context.compile(source, options, c_only,
obj_only)
File
"C:\Python23\Lib\site-packages\Pyrex\Compiler\Main.py",
line 167, in compile
scope = self.find_module(module_name, pos =
initial_pos, need_pxd = 0)
File
"C:\Python23\Lib\site-packages\Pyrex\Compiler\Main.py",
line 82, in find_module
pxd_tree.analyse_declarations(scope)
File
"C:\Python23\Lib\site-packages\Pyrex\Compiler\Nodes.py",
line 73, in analyse_declarations
self.body.analyse_declarations(env)
File
"C:\Python23\Lib\site-packages\Pyrex\Compiler\Nodes.py",
line 1125, in analyse_declarations
stat.analyse_declarations(env)
File
"C:\Python23\Lib\site-packages\Pyrex\Compiler\Nodes.py",
line 2194, in analyse_declarations
base_class_scope =
env.find_module(self.base_class_module)
TypeError: find_module() takes exactly 3 arguments (2
given)
Thank you for helping
Alain Pointdexter
Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout !
Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/
More information about the Pyrex
mailing list