-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive for UPPER_CASE variable name #3132
Comments
Note: it seems the bug is actually because pylint treats the import random
def compute(number):
return 2 * number
if __name__ == "__main__":
number = random.randint(1, 10) produces:
The re-use of |
We probably should change the interpretation of "constant" as right now it's not entirely correct. There was another recent issue about the same thing and I agree that our interpretation of "constant" from PEP 8 was erroneous. |
This check causes many false positives, especially for global variables used in simple scripts. Looks like this will be fixed in Pylint 2.5.0, though. It's already been integrated into the main branch: pylint-dev/pylint@3422e4a Also see relevant issues that motivated the change: - pylint-dev/pylint#3111 - pylint-dev/pylint#3132 The latest changelog with the fix mentioned under 2.5.0 changes: https://github.com/PyCQA/pylint/blob/f2f4e6f42416644471ab003d4df7ecf052c3c411/ChangeLog
Move all CLI script code under `if __name__ == "__main__"` to separate module-level `main()` methods that serve as the entrypoint. This fixes many invalid-name errors and all redefined-outer-name errors. Sort imports alphabetically, and group them in the order: builtins, 3rd-parties, local stuff. This eliminates import-related warnings. Other minor warnings are dealt with by fixing the code, or disabling the warning if it is a false positive. Notably, refactor warnings (Rxxxx) are not handled. These require considerably more thought to work out. Since VS code doesn't show them as errors, we're in no rush. Unrelated to Pylint warnings: In sample scripts, remove the statements that directly added the project root to sys.path. This was a hack used to make d2txt.py importable in sample scripts. Now that we have `pip install -e .`, there's no need to tamper with sys.path. Note: As of Pylint 2.4.4, it incorrectly believes that all module-level variables are constants, and emits invalid-name on them. This check had to be disabled via comments sprinkled throughout the codebase. Looks like this will be fixed in Pylint 2.5.0, though. It's already been integrated into the main branch: pylint-dev/pylint@3422e4a Also see relevant issues that motivated the change: - pylint-dev/pylint#3111 - pylint-dev/pylint#3132 The latest changelog with the fix mentioned under 2.5.0 changes: https://github.com/PyCQA/pylint/blob/f2f4e6f42416644471ab003d4df7ecf052c3c411/ChangeLog
Move all CLI script code under `if __name__ == "__main__"` to separate module-level `main()` methods that serve as the entrypoint. This fixes many invalid-name errors and all redefined-outer-name errors. Sort imports alphabetically, and group them in the order: builtins, 3rd-parties, local stuff. This eliminates import-related warnings. Other minor warnings are dealt with by fixing the code, or disabling the warning if it is a false positive. Notably, refactor warnings (Rxxxx) are not handled. These require considerably more thought to work out. Since VS code doesn't show them as errors, we're in no rush. Unrelated to Pylint warnings: In sample scripts, remove the statements that directly added the project root to sys.path. This was a hack used to make d2txt.py importable in sample scripts. Now that we have `pip install -e .`, there's no need to tamper with sys.path. Note: As of Pylint 2.4.4, it incorrectly believes that all module-level variables are constants, and emits invalid-name on them. This check had to be disabled via comments sprinkled throughout the codebase. Looks like this will be fixed in Pylint 2.5.0, though. It's already been integrated into the main branch: pylint-dev/pylint@3422e4a Also see relevant issues that motivated the change: - pylint-dev/pylint#3111 - pylint-dev/pylint#3132 The latest changelog with the fix mentioned under 2.5.0 changes: https://github.com/PyCQA/pylint/blob/f2f4e6f42416644471ab003d4df7ecf052c3c411/ChangeLog
Move all CLI script code under `if __name__ == "__main__"` to separate module-level `main()` methods that serve as the entrypoint. This fixes many invalid-name errors and all redefined-outer-name errors. Sort imports alphabetically, and group them in the order: builtins, 3rd-parties, local stuff. This eliminates import-related warnings. Other minor warnings are dealt with by fixing the code, or disabling the warning if it is a false positive. Notably, refactor warnings (Rxxxx) are not handled. These require considerably more thought to work out. Since VS code doesn't show them as errors, we're in no rush. Unrelated to Pylint warnings: In sample scripts, remove the statements that directly added the project root to sys.path. This was a hack used to make d2txt.py importable in sample scripts. Now that we have `pip install -e .`, there's no need to tamper with sys.path. Note: As of Pylint 2.4.4, it incorrectly believes that all module-level variables are constants, and emits invalid-name on them. This check had to be disabled via comments sprinkled throughout the codebase. Looks like this will be fixed in Pylint 2.5.0, though. It's already been integrated into the main branch: pylint-dev/pylint@3422e4a Also see relevant issues that motivated the change: - pylint-dev/pylint#3111 - pylint-dev/pylint#3132 The latest changelog with the fix mentioned under 2.5.0 changes: https://github.com/PyCQA/pylint/blob/f2f4e6f42416644471ab003d4df7ecf052c3c411/ChangeLog
Move all CLI script code under `if __name__ == "__main__"` to separate module-level `main()` methods that serve as the entrypoint. This fixes many invalid-name errors and all redefined-outer-name errors. Sort imports alphabetically, and group them in the order: builtins, 3rd-parties, local stuff. This eliminates import-related warnings. Other minor warnings are dealt with by fixing the code, or disabling the warning if it is a false positive. Notably, refactor warnings (Rxxxx) are not handled. These require considerably more thought to work out. Since VS code doesn't show them as errors, we're in no rush. Unrelated to Pylint warnings: In sample scripts, remove the statements that directly added the project root to sys.path. This was a hack used to make d2txt.py importable in sample scripts. Now that we have `pip install -e .`, there's no need to tamper with sys.path. Note: As of Pylint 2.4.4, it incorrectly believes that all module-level variables are constants, and emits invalid-name on them. This check had to be disabled via comments sprinkled throughout the codebase. Looks like this will be fixed in Pylint 2.5.0, though. It's already been integrated into the main branch: pylint-dev/pylint@3422e4a Also see relevant issues that motivated the change: - pylint-dev/pylint#3111 - pylint-dev/pylint#3132 The latest changelog with the fix mentioned under 2.5.0 changes: https://github.com/PyCQA/pylint/blob/f2f4e6f42416644471ab003d4df7ecf052c3c411/ChangeLog
Steps to reproduce
Code:
Current behavior
The second error implies
number
is constant, which it is not.pylint --version output
The text was updated successfully, but these errors were encountered: