Relative imports

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    #1

    Relative imports

    Why do relative imports cause warnings in PyLint?
    A warning like this:
    ID:W0403 Relative import 'myPythonFileIn TheSameFolder'
    When the import is like:
    from myPythonFileInT heSameFolder import MyClass

  • Michael Hoffman

    #2
    Re: Relative imports

    Chris wrote:[color=blue]
    > Why do relative imports cause warnings in PyLint?[/color]


    --
    Michael Hoffman

    Comment

    • Kent Johnson

      #3
      Re: Relative imports

      Michael Hoffman wrote:[color=blue]
      > Chris wrote:
      >[color=green]
      >> Why do relative imports cause warnings in PyLint?[/color]
      >
      >
      > http://www.python.org/peps/pep-0328....solute-imports[/color]

      I notice that this section says that
      from __future__ import absolute_import

      will be a feature of Python 2.4. Apparently it didn't make the cut. I've posted a bug report.

      Kent

      Comment

      • Chris

        #4
        Re: Relative imports

        After reading that link I tried to change my imports like this:
        " from .myPythonFileIn TheSameFolder import MyClass"

        Well, this caused an error in PyLint:
        Encountered "." at line 1, column 6. Was expecting one of: "or" ...
        "and" ... "not" ... "is" ... "in" ... "lambda" ...
        "if" ... "else" ... "elif" ... "while" ... "for" ...
        "try" ... "except" ... "def" ... "class" ...
        "finally" ... "print" ... "pass" ... "break" ...
        "continue" ... "return" ... "yield" ... "import" ...
        "from" ... "del" ... "raise" ... "global" ... "exec"
        .... "assert" ... "as" ... <NAME> ...
        ID:E0001 invalid syntax

        I'm getting more and more confused...
        How can I correctly do a relative import ?

        Comment

        • Kent Johnson

          #5
          Re: Relative imports

          Chris wrote:[color=blue]
          > After reading that link I tried to change my imports like this:
          > " from .myPythonFileIn TheSameFolder import MyClass"[/color]

          This style of import is not yet implemented.
          [color=blue]
          > I'm getting more and more confused...
          > How can I correctly do a relative import ?[/color]

          I think your choices are
          - keep doing what you have been doing and ignore the warnings from PyLint
          - keep doing what you have been doing and turn off the warnings from PyLint
          - rewrite your imports to be absolute imports

          Kent

          Comment

          Working...