0

I created a file (permissions.py) in the main app(main_app). Now I imported it to an actual app view (actual_app):

from main_app.permissions import SomeClass

Pylint is throwing errors:

E0611: No name 'permissions' in module 'main_app' (no-name-in-module)
E0401: Unable to import 'main_app.permissions' (import-error)

However if I excluded E0611, E0401 in the error checking, my program works perfectly fine. Any idea on this?

Additional findings: if I do:

from ..main_app.permissions import SomeClass

Lint success, but now the actual program fails. Seems that it cant import the module the django way.

ACD
  • 1,431
  • 1
  • 8
  • 24
  • Are you using virtual env? If you are using virtual environment, it could be that ```pylint``` is unable to 'see' the modules. More: https://stackoverflow.com/questions/17923090/pylint-doesnt-point-to-virtualenv-python – drd Feb 14 '20 at 06:37
  • Yes I am. However, I think this is a pylint bug on django. I think it's checking how python naturally import files but in this case, django is automatically importing from apps instead of directory. – ACD Feb 14 '20 at 06:48
  • is there an `__init__.py` file in `main_app`? – 4140tm Feb 14 '20 at 09:31
  • @4140tm yes there is – ACD Feb 14 '20 at 09:42

1 Answers1

0

I can't tell whether you're having the same issue, but I encountered this as well.

When there is both a file foo.py, and a folder foo, pylint seems not to know which one to follow. Python itself is smart enough that if there is a file foo/bar.py with a class baz, from foo.bar import baz works fine.

But pylint seems to only look at foo.py, and complains if this doesn't contain something called bar.

A workaround is to rename your file foo.py. Although it's not really a solution, it gets working code without the pylint-warning.

Emil Bode
  • 1,784
  • 8
  • 16