-
Notifications
You must be signed in to change notification settings - Fork 6.8k
5 undefined names in Python code #8270
Comments
@apache/mxnet-committers: This issue has been inactive for the past 90 days. It has no label and needs triage. For general "how-to" questions, our user forum (and Chinese version) is a good place to get help. |
Sorry could you clarify the issue and give a bit of context? |
These are variables that are not defined in the current context which can raise NameError at runtime. Often they are typos or missing imports or code refactoring errors or things like basestring or xrange() being defined in Python 2 but being removed in Python 3. Just try reading thru the code as if you were the Python interpreter and ask yourself "Where is this variable defined?". |
Oh I understand now, that's some static code analysis right? Thanks for running that, seems like some files need fixing. |
Are there any specific advantages that flake8 has over pylint? |
flake8 will find undefined names that pylint will not because flake8 makes an abstract syntax tree for each Python file and plyint does not. This also explains why flake8 gives different results in Python 2 and Python 3 (the have different ASTs while pylint does not. Take running code like isinstance(unicode('Hello'), basestring) through pylint on Python 2 and Python 3 and see if there are differences in the output. Now try same with flake8. |
I take it back... You are right. PyLint is now able to find undefined names. $ python3 -m pylint *.py
|
flake8 testing of https://github.com/apache/incubator-mxnet on Python 3.7.0 $ flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
|
@cclauss I'm working on fixing these errors. Will add you to the PRs as I submit them. |
Pylint reports undefined variables when there is a wildcard import. The list from Pylint is at #11904 |
flake8 (on Python 3.7.0) moved from finding 22 undefined names down to 19. flake8 testing of https://github.com/apache/incubator-mxnet on Python 3.7.0 $ flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
|
With the merge of #11982, flake8 (on Python 3) is now down to 10 undefined names: flake8 testing of https://github.com/apache/incubator-mxnet on Python 3.7.0 $ flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
|
|
@vandanavk Taking a look. |
@vandanavk Thanks for the catch! Should be addressed in #12147 |
Thanks @KellenSunderland @cclauss I don't see the errors
I've tried flake8 and pylint, Python2 and Python3. Although I do see
After these are fixed, I'll add "undefined-variable" to pylintrc in the CI build. This will check future commits to python/mxnet. |
|
See PEP8 for reasons why star imports are for the birds... On the |
flake8 testing of https://github.com/apache/incubator-mxnet on Python 3.7.0 $ flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
|
@hqucms Could you have a look at these f3070fb#r30092025? |
@vandanavk Thank you for spotting this! I made a fix in #12211. |
@cclauss looks like all the PRs for fixing these errors are merged. Do you think this issue can be closed now? |
Yes. |
Undefined names can raise NameError at runtime.
flake8 testing of https://github.com/apache/incubator-mxnet on Python 2.7.14
$ flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
The text was updated successfully, but these errors were encountered: