views:

1649

answers:

3

I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module settings that defines a settings object. I import that in module b and assign an attribute with:

from settings import settings
settings.main = object()

In some of my code--but not all of it, statements like:

from settings import settings
print settings.main 

... generate "Undefined variable from import: main" messages in the Eclipse code error pane, even though the code runs without a problem. How can I correct these?

A: 

define main in the module? It seems like the error message clear, and you have code that fixes it, so why the question?

Your code isn't generating false errors, main is most likely not getting defined. perhaps if you post some code from your settings module, someone can give you a better answer.

GSto
The code analysis tools within PyDev are generating false errors. This is valid Python code, and runs without a problem.
Chris B.
+7  A: 

For code in your project, the only way is adding a comment saying that you expected that (the static code-analysis only sees what you see, not runtime info -- if you opened that module yourself, you'd have no indication that main was expected).

You can use ctrl+1 in a line with an error and pydev will present you an option to add a comment to ignore that error.

If it was some external module, you could add it to the forced builtins so that it was forced to be analyzed by a running shell with runtime information (see http://pydev.org/manual_101_interpreter.html for details).

Fabio Zadrozny