I have a lot of datamodels in a datamodel/ directory and I don't want to import them one by one so I did:
from datamodel import * # pylint:disable=unused-wildcard-import
and then further on I did:
datamodel_file.DataModelClass(db_server)
I get the following errors in VS Code:
Undefined variable 'datamodel_file' (pylint(undefined-variable)[22,27] Undefined variable: 'datamodel_file' (Python(undefined-variable)[22,27]
A few problems with this:
- I don't understand why VS Code/PyLint thinks that this variable is undefined as the code runs fine when I debug it
- Why are there 2 error messages?
- I tried to disable the pylint message as a quick try-and-see-what-happens by doing:
datamodel_file.DataModelClass(db_server) # pylint:disable=undefined-variableThis has the effect of disabling the error from pylint but that other error from Python still remains.
How should I fix this error?
pylintdoes a static analysis of your imports. It won't find variables that require code to be executed to bring the variable into existence. This includes dynamically created variables and stuff loaded from DLLs at runtime.