Skip to content

Commit 077235e

Browse files
authored
Remove docs and code associated with the removed W0623 (redefine-in-handler) checker (#4543)
* remove docs and code associated with the removed W0623 checker
1 parent a1e1774 commit 077235e

File tree

5 files changed

+4
-49
lines changed

5 files changed

+4
-49
lines changed

CONTRIBUTORS.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,5 @@ contributors:
501501
* Fabian Damken: contributor
502502

503503
* Markus Siebenhaar: contributor
504+
505+
* Lorena Buciu (lorena-b): contributor

pylint/checkers/base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,8 +1986,6 @@ def visit_assignname(self, node):
19861986
utils.safe_infer(assign_type.value), astroid.Const
19871987
):
19881988
self._check_name("const", node.name, node)
1989-
elif isinstance(assign_type, astroid.ExceptHandler):
1990-
self._check_name("variable", node.name, node)
19911989
elif isinstance(
19921990
assign_type, astroid.AnnAssign
19931991
) and utils.is_assign_name_annotated_with(node, "Final"):
@@ -2062,10 +2060,6 @@ def _should_exempt_from_invalid_name(node):
20622060
return True
20632061
return False
20642062

2065-
if utils.is_inside_except(node):
2066-
clobbering, _ = utils.clobber_in_except(node)
2067-
if clobbering:
2068-
return
20692063
if self._name_allowed_by_regex(name=name):
20702064
return
20712065
if self._name_disallowed_by_regex(name=name):

pylint/checkers/utils.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,6 @@ class InferredTypeError(Exception):
277277
pass
278278

279279

280-
def is_inside_except(node):
281-
"""Returns true if node is inside the name of an except handler."""
282-
current = node
283-
while current and not isinstance(current.parent, astroid.ExceptHandler):
284-
current = current.parent
285-
286-
return current and current is current.parent.name
287-
288-
289280
def is_inside_lambda(node: astroid.node_classes.NodeNG) -> bool:
290281
"""Return true if given node is inside lambda"""
291282
parent = node.parent
@@ -307,31 +298,6 @@ def get_all_elements(
307298
yield node
308299

309300

310-
def clobber_in_except(
311-
node: astroid.node_classes.NodeNG,
312-
) -> Tuple[bool, Optional[Tuple[str, str]]]:
313-
"""Checks if an assignment node in an except handler clobbers an existing
314-
variable.
315-
316-
Returns (True, args for W0623) if assignment clobbers an existing variable,
317-
(False, None) otherwise.
318-
"""
319-
if isinstance(node, astroid.AssignAttr):
320-
return True, (node.attrname, f"object {node.expr.as_string()!r}")
321-
if isinstance(node, astroid.AssignName):
322-
name = node.name
323-
if is_builtin(name):
324-
return True, (name, "builtins")
325-
326-
stmts = node.lookup(name)[1]
327-
if stmts and not isinstance(
328-
stmts[0].assign_type(),
329-
(astroid.Assign, astroid.AugAssign, astroid.ExceptHandler),
330-
):
331-
return True, (name, "outer scope (line %s)" % stmts[0].fromlineno)
332-
return False, None
333-
334-
335301
def is_super(node: astroid.node_classes.NodeNG) -> bool:
336302
"""return True if the node is referencing the "super" builtin function"""
337303
if getattr(node, "name", None) == "super" and node.root().name == BUILTINS_NAME:

pylint/checkers/variables.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,6 @@ def _has_locals_call_after_node(stmt, scope):
457457
"redefined-builtin",
458458
"Used when a variable or function override a built-in.",
459459
),
460-
"W0623": (
461-
"Redefining name %r from %s in exception handler",
462-
"redefine-in-handler",
463-
"Used when an exception handler assigns the exception to an existing name",
464-
),
465460
"W0631": (
466461
"Using possibly undefined loop variable %r",
467462
"undefined-loop-variable",
@@ -731,7 +726,7 @@ def visit_module(self, node):
731726
self._postponed_evaluation_enabled = is_postponed_evaluation_enabled(node)
732727

733728
for name, stmts in node.locals.items():
734-
if utils.is_builtin(name) and not utils.is_inside_except(stmts[0]):
729+
if utils.is_builtin(name):
735730
if self._should_ignore_redefined_builtin(stmts[0]) or name == "__doc__":
736731
continue
737732
self.add_message("redefined-builtin", args=name, node=stmts[0])
@@ -819,8 +814,6 @@ def visit_functiondef(self, node):
819814
return
820815
globs = node.root().globals
821816
for name, stmt in node.items():
822-
if utils.is_inside_except(stmt):
823-
continue
824817
if name in globs and not isinstance(stmt, astroid.Global):
825818
definition = globs[name][0]
826819
if (

tests/functional/r/redefined_argument_from_local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pylint: disable=missing-docstring, unused-variable, unused-argument
2-
# pylint: disable=redefined-outer-name, invalid-name, redefine-in-handler
2+
# pylint: disable=redefined-outer-name, invalid-name
33

44
def test_redefined_in_with(name):
55
with open('something') as name: # [redefined-argument-from-local]

0 commit comments

Comments
 (0)