#1297 Several import problems with -python

None
closed
python (259)
6
2013-12-24
2012-12-23
Paweł Tomulik
No

Hello,

I was working last few days with swig/python and faced several
issues related to imports (r13995 of Source/Modules/python.cxx).

I attach prepared few cases for testing with description for each one.
To give some examples here in text, consider:

  1. Same module names in different packages (https://sourceforge.net/p/swig/bugs/1293/), e.g.:

    P1/init.py (empty)
    P1/Foo_Mod.i (with 'class P1Foo{};')
    P2/Foo_Mod.i (with 'class P2Foo : P1Foo{}' and '%import <P1 Foo_Mod.i="">')

  2. "Pre-importing" from init.py (broken due to applied patch #3590522):

    P1/ini.py (empty)
    P1/S1/Foo_Mod.i (with 'class P1S1Foo {};' )
    P1/S1/Bar_Mod.i (with 'class P1S1Bar : P1S1Foo {};' and '%import <P1 S1="" Foo_Mod.i="">')
    P1/S1/init.py (with 'from Bar_Mod import P1S1Bar')

I've worked-out a patch (tested with pytho2.7 and 3.2), but it should be
re-developed from scratch by someone knowing the internals of swig. I'll attach it
here in comments.

1 Attachments

Related

Bugs: #1297

Discussion

  • Paweł Tomulik
    Paweł Tomulik
    2012-12-23

    The patch.
    For testing, the patch shall be applied to r13995 revision of Source/Modules/python.cxx.
    Note, that it cancels the 'fully qualified package names' introduced by patch #3590522.

     
    Last edit: Paweł Tomulik 2012-12-23
  • Bill Spotz
    Bill Spotz
    2013-01-31

    I have a wrapping project that involves many nested C++ namespaces, and I am attempting to create a Python package that mimics the namespaces with modules. I was running into a problem where base classes would not be properly qualified. For example, I might have a class AbstractGroup that derives from TimeDependent.AbstractGroup. The generated Python was

    class AbstractGroup(AbstractGroup):

    which will always raise a NameError because AbstractGroup is not defined before you try to define it.

    Pawel provided his patched version of swig to me and I was able to verify that it fixed my problem. My project depends upon this fix. I am attaching a somewhat simplified example of the problem: a directory of header files and interface files that demonstrate the problem with swig 2.0.9. This could be used as a test to demonstrate the issue and verify the fix.

     
    Attachments
  • Paweł Tomulik
    Paweł Tomulik
    2013-01-31

    Hi,

    To be clear, the patched version is that from
    https://github.com/swig/swig/pull/7

    W dniu 31.01.2013 21:53, Bill Spotz pisze:

    I have a wrapping project that involves many nested C++ namespaces,
    and I am attempting to create a Python package that mimics the
    namespaces with modules. I was running into a problem where base
    classes would not be properly qualified. For example, I might have a
    class AbstractGroup that derives from TimeDependent.AbstractGroup. The
    generated Python was

    class AbstractGroup(AbstractGroup):

    which will always raise a NameError because AbstractGroup is not
    defined before you try to define it.

    Pawel provided his patched version of swig to me and I was able to
    verify that it fixed my problem. My project depends upon this fix. I
    am attaching a somewhat simplified example of the problem: a directory
    of header files and interface files that demonstrate the problem with
    swig 2.0.9. This could be used as a test to demonstrate the issue and
    verify the fix.

    Attachment: Example.tgz (731 Bytes; application/x-gzip)


    [bugs:#1297] http://sourceforge.net/p/swig/bugs/1297/ Several
    import problems with -python

    Status: open
    Labels: python
    Created: Sun Dec 23, 2012 11:20 PM UTC by Paweł Tomulik
    Last Updated: Sun Dec 23, 2012 11:20 PM UTC
    Owner: nobody

    Hello,

    I was working last few days with swig/python and faced several
    issues related to imports (r13995 of Source/Modules/python.cxx).

    I attach prepared few cases for testing with description for each one.
    To give some examples here in text, consider:

    1.

    Same module names in different packages
    (https://sourceforge.net/p/swig/bugs/1293/), e.g.:
    
    P1/*init*.py (empty)
    P1/Foo_Mod.i (with 'class P1Foo{};')
    P2/Foo_Mod.i (with 'class P2Foo : P1Foo{}' and '%import Foo_Mod.i>')
    

    2.

    "Pre-importing" from *init*.py (broken due to applied patch #3590522):
    
    P1/*ini*.py (empty)
    P1/S1/Foo_Mod.i (with 'class P1S1Foo {};' )
    P1/S1/Bar_Mod.i (with 'class P1S1Bar : P1S1Foo {};' and '%import
    S1Foo_Mod.i>')
    P1/S1/*init*.py (with 'from Bar_Mod import P1S1Bar')
    

    I've worked-out a patch (tested with pytho2.7 and 3.2), but it should be
    re-developed from scratch by someone knowing the internals of swig.
    I'll attach it
    here in comments.


    Sent from sourceforge.net because you indicated interest in
    https://sourceforge.net/p/swig/bugs/1297/

    To unsubscribe from further messages, please visit
    https://sourceforge.net/auth/prefs/

    --
    Pawel Tomulik

     

    Related

    Bugs: #1297

  • William Fulton
    William Fulton
    2013-12-24

    • status: open --> closed
    • assigned_to: William Fulton
    • Group: -->