Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spyder IDE complaining about unable to detect undefined names

Using Windows 10 with Spyder IDE running Python 3.5. I am seeing following in the __init__.py file complaining about unable to detect undefined names:

enter image description here

However, it seems __init__.py file is in the same folders as all other files.

enter image description here

So why it is complaining? I tried to remove the leading dot in the front, but it still complains. Please give me some pointers.

like image 286
Nick X Tsui Avatar asked May 20 '18 20:05

Nick X Tsui


2 Answers

Your IDE is complaining, not Python. When you do from simple import *, you import everything exposed by simple. This is typically not recommended because it pollutes the global namespace and may implicitly overwrite an existing object.

You get a warning instead of an error because this behavior is not always bad. Having an __init__.py file that exposes objects from sub-modules is a very common pattern. As long as you understand the potential risks, just silence the warning:

from .input import *  # NOQA

If your modules don't expose many objects, just import them by name:

from .input import A, B, C

This has the benefit of allowing Python code analysis tools to better understand your code and warn you of potential issues.

like image 177
Blender Avatar answered Sep 21 '22 00:09

Blender


I had the same problem, the asterisk. I located the modules to call them as indicated by Blender

and it was solved

One

change the asterisk by the names of the modules

Two

locate the names that have conflict

Three

and as you add them up, the error will be silenced

Four

Thanks for your comments, they helped me with the problem I had

like image 34
Joe Llerena Avatar answered Sep 18 '22 00:09

Joe Llerena