Skip to content

Commit

Permalink
No longer emit invalid-name for non-constants found at module level.
Browse files Browse the repository at this point in the history
Pylint was taking the following statement from PEP-8 too far, considering
all module level variables as constants, which is not what the statement is saying:

`Constants are usually defined on a module level and written in
all capital letters with underscores separating words.`

Close #3111
Close #3132
  • Loading branch information
PCManticore committed Nov 8, 2019
1 parent 09cd08c commit 3422e4a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ Release date: TBA

Close #3224

* No longer emit ``invalid-name`` for non-constants found at module level.

Pylint was taking the following statement from PEP-8 too far, considering
all module level variables as constants, which is not what the statement is saying:

`Constants are usually defined on a module level and written in
all capital letters with underscores separating words.`

Close #3111
Close #3132

* Allow ``implicit-str-concat-in-sequence`` to be emitted for string juxtaposition

Close #3030
Expand Down
8 changes: 5 additions & 3 deletions pylint/checkers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1886,9 +1886,11 @@ def visit_assignname(self, node):
if isinstance(utils.safe_infer(assign_type.value), astroid.ClassDef):
self._check_name("class", node.name, node)
else:
if not _redefines_import(node):
# Don't emit if the name redefines an import
# in an ImportError except handler.
# Don't emit if the name redefines an import
# in an ImportError except handler.
if not _redefines_import(node) and isinstance(
utils.safe_infer(assign_type.value), astroid.Const
):
self._check_name("const", node.name, node)
elif isinstance(assign_type, astroid.ExceptHandler):
self._check_name("variable", node.name, node)
Expand Down
3 changes: 3 additions & 0 deletions tests/functional/n/name_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def _private_scope_function_with_long_descriptive_name():
return 12

LONG_CONSTANT_NAME_IN_PUBLIC_SCOPE_ARE_OKAY = True
# We don't emit for non-const nodes
good_name_for_funcs = lambda: None
good_name_for_lists = [1, 2, 3]

class _AnExceptionalExceptionThatOccursVeryVeryRarely(Exception):
"""A very exceptional exception with a nice descriptive name"""
Expand Down

0 comments on commit 3422e4a

Please sign in to comment.