pylint #62727 import issue [open]
Consider 2 files in the same folder, one importing the other.
This runs fine from the folder holding the 2 files or from any other folder.
Pylinting is fine from the folder holding the 2 files but not from any other folder as it then results in;
[F0401] Unable to import 'module'
TMHO this is not right and therefore I added;
import sys
to; | |
priority | normal |
---|---|
type | bug |
done in | <not specified> |
closed by | <not specified> |
Comments
-
2011/08/01 14:10, written by anon
-
2011/08/01 15:23, written by anon
-
2011/08/01 15:44, written by anon
-
2011/08/01 15:50, written by sthenault
-
2011/08/01 19:01, written by anon
-
2011/08/04 08:18, written by sthenault
- from __future__ import absolute_import
- I agree, though if this change in python 3, it won't motivate a fix
add commentThis looks like a classic import mistake to me. You cannot import from directories that are not on sys.path. The first case works because Python has the working directory on sys.path.
Exactly, and that is why pylint should also add the current working folder to sys.path just like Python does.
Correction, it is not the current working folder but the folder holding the script that is executed/linted.
So pylint should add the folder holding the script that is linted to sys.path
1. does this work with absolute import activated ?
2. don't forget that pylint is not python, and it has no notion of
__main__ module. Don't playing this directories / sys.path was
originally a design choice, because I thought it was discouraging
bad practices. I'm not against changing this, but I'll have to be
convinced we should
1. How do I activate absolute import?
2. pylint should not fail when handling code that Python itself handles correctly. If it is bad practice pylint should issue a warning in stead of failing.
A quick test shows that it still works in python 3, hence pylint should be fixed