Archived

This forum has been archived. Please start a new discussion on GitHub.

slice2py generates code not usable by Python 3.3

Using: Windows 7 (32-bit), Python 3.3.3, Ice-3.5.1

nested.ice:
module outer {
    module inner {
        interface foo {
            void bar();
        };
    };
};

Running slice2py on this slice definition yields an 'outer' package which uses an implict relative import for the generated 'inner' package:

outer\__init__.py:
# Generated by slice2py - DO NOT EDIT!
#

import Ice
Ice.updateModule("outer")

# Modules:
import nested_ice

# Submodules:
import [B]inner[/B]

Importing this gives the error:
>>> import outer.inner
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".\outer\__init__.py", line 11, in <module>
    import inner
ImportError: No module named 'inner'

If I manually edit outer\__init__.py to use explicit relative imports, like so:
# Generated by slice2py - DO NOT EDIT!
#

import Ice
Ice.updateModule("outer")

# Modules:
import nested_ice

# Submodules:
[B]from . import inner[/B]

...everything works as expected. I understand implicit relative imports were removed in Python 3. With Python 2.6 and Ice 3.4, this is not an issue since implicity relative imports are allowed. Is this a bug with slice2py v3.5.x or am I missing something?

I've also looked at this post, but would like to stay away from using Ice.updateModules() as per the warning in that thread against its use. Using this undocumented API with the ''--no-package" option of slice2py does fix the issue, however.

Comments

  • mes
    mes California
    Hi,

    Welcome to the forum, and thanks for reporting this. We're looking into it.

    Regards,
    Mark
  • mes
    mes California
    Hi,

    I agree, it's a bug in slice2py (I've moved this post to the Bug Reports section).

    I've attached a patch that changes the compiler to use explicit relative imports as you mentioned. I've tested it with Python 2.7 and 3.3. You can apply the patch to an Ice 3.5.1 source distribution with these commands:

    cd Ice-3.5.1
    patch -p1 < slice2py.patch.txt

    Regards,
    Mark
  • Great! Thanks for your help.