#680 Python import and class - name clash

closed-fixed
szager
python (259)
5
2011-04-14
2006-05-11
nitro
No

Hello,

I have two interface files:

<System.i>
%module(package = "pkg") System

<UserInterface.i>
%module(package = "pkg") UserInterface
%import "System.i"

class System
{};

This is then wrapped by swig something like

<UserInterface.py>
class System: ....
import System

As you can clearly see, the System module will override
the System class. So when doing

import pkg.UserInterface
classInstance = pkg.UserInterface.System()

this fails, because pkg.UserInterface.System points to
pkg.System and not the desired class. One workaround
would be to do something like

import pkg.System

in the UserInterface.py file. So swig should not import
only by module name, but also use the surrounding
package name to avoid name clashes as the one above.

-Matthias

Discussion

  • nitro

    nitro - 2006-05-11
    • labels: -->
     
  • nitro

    nitro - 2006-05-11
    • labels: --> python
     
  • szager

    szager - 2011-04-14

    This is fixed in the upcoming swig release, 2.0.4. The "import System" statement is moved up in UserInterface.py, before the declaration of "class System". So, the "class System" declaration owns the "System" symbol in package "UserInterface"

     
  • szager

    szager - 2011-04-14
    • assigned_to: nobody --> szager
    • status: open --> closed-fixed
     

Log in to post a comment.