summaryrefslogtreecommitdiff
path: root/pylint/checkers/variables.py
diff options
context:
space:
mode:
Diffstat (limited to 'pylint/checkers/variables.py')
-rw-r--r--pylint/checkers/variables.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index c7fd63184..3d7eadc20 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -667,6 +667,15 @@ class VariablesChecker(BaseChecker):
"help": "Tells whether unused global variables should be treated as a violation.",
},
),
+ (
+ "allowed-redefined-builtins",
+ {
+ "default": (),
+ "type": "csv",
+ "metavar": "<comma separated list>",
+ "help": "List of names allowed to shadow builtins",
+ },
+ ),
)
def __init__(self, linter=None):
@@ -829,8 +838,10 @@ class VariablesChecker(BaseChecker):
"redefined-outer-name", args=(name, line), node=stmt
)
- elif utils.is_builtin(name) and not self._should_ignore_redefined_builtin(
- stmt
+ elif (
+ utils.is_builtin(name)
+ and not self._allowed_redefined_builtin(name)
+ and not self._should_ignore_redefined_builtin(stmt)
):
# do not print Redefining builtin for additional builtins
self.add_message("redefined-builtin", args=name, node=stmt)
@@ -1752,6 +1763,9 @@ class VariablesChecker(BaseChecker):
return False
return stmt.modname in self.config.redefining_builtins_modules
+ def _allowed_redefined_builtin(self, name):
+ return name in self.config.allowed_redefined_builtins
+
def _has_homonym_in_upper_function_scope(self, node, index):
"""
Return True if there is a node with the same name in the to_consume dict of an upper scope