Search code examples
pythonrelative-pathpython-packaging

python: What's the rationale behind not allowing * in relative imports?


What's the rationale behind not allowing * in relative imports? e.g.

from ..new_tool import *

or doing a relative import directly:

import ..new_tool

Solution

  • The reason the latter is prohibited is that ..new_tool is not usable in an expression (PEP 328):

    The reason import .foo is prohibited is because after

        import XXX.YYY.ZZZ
    

    then XXX.YYY.ZZZ is usable in an expression. But

        .moduleY
    

    is not usable in an expression.

    Since *-imports should only ever be a quick hack while in development, I suspect the functionality for relative *-imports was left out because it's not necessary.