[Python-Dev] Fix import errors to have data
Phillip J. Eby
pje at telecommunity.com
Mon Aug 2 18:57:51 CEST 2004
At 10:01 AM 8/2/04 -0400, Jim Fulton wrote:
>Phillip J. Eby wrote:
>>At 08:28 AM 7/30/04 -0400, Jim Fulton wrote:
>>
>>>The problem with Python's current package system is that it's not possible,
>>>in general, to write packages that can be moved around within the package
>>>system, because relative imports aren't reobust or flexible enough.
>>>PEP 328 would fix this. PEP 328 would allow creation of packages that
>>>worked regardless of where there were places or that worked relative
>>>to a containing package regardless of where that was placed. You could
>>>then have different module spaces expressed by adding a new layer of
>>>top-level
>>>modules. You wouldn't need any new machinery beyond PEP 328.
>>
>>Hm. The concept I'm proposing would allow code to be used in a module
>>space without needing to know about module spaces or be written to
>>co-operate in such a fashion. If you can make everybody conform to some
>>sort of coding standard, you wouldn't even need PEP 328 to accomplish
>>your goal. ;)
>
>No, I don't think this is right. PEP 328 should allow you to create
>module spaces using container packages. For your example, we create
>two top-level packages, space1 and space 2. You put version x of PIL
>in space1. That package's absolute name is space1.PIL. You put version y
>of PIL in space2, creating space2.PIL. Now you put the products that
>depend on version x of PIL in space1. You put the products that depend
>on version y of PIL on space 2. The products mist use relative imports
>to import from PIL:
>
> from ..PIL import somePILmodule
>
>For this to work, PIL also has to use relative imports to import it's own
>modules.
As I said, if you get to make PIL and everybody else rewrite their imports,
you can do whatever you want to already. :) The point of my proposal is
to make it possible *without* rewriting imports, in versions of Python from
2.2 up.
More information about the Python-Dev
mailing list