Skip to content

Commit cb89612

Browse files
authored
Remove most typing.cast() calls (#4995)
1 parent a3f3405 commit cb89612

File tree

3 files changed

+3
-17
lines changed

3 files changed

+3
-17
lines changed

pylint/checkers/classes.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"""
4848
import collections
4949
from itertools import chain, zip_longest
50-
from typing import List, Pattern, cast
50+
from typing import List, Pattern
5151

5252
import astroid
5353
from astroid import nodes
@@ -907,7 +907,6 @@ def leave_classdef(self, node: nodes.ClassDef) -> None:
907907

908908
def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
909909
for function_def in node.nodes_of_class(nodes.FunctionDef):
910-
function_def = cast(nodes.FunctionDef, function_def)
911910
if not is_attr_private(function_def.name):
912911
continue
913912
parent_scope = function_def.parent.scope()
@@ -918,7 +917,6 @@ def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
918917
):
919918
continue
920919
for attribute in node.nodes_of_class(nodes.Attribute):
921-
attribute = cast(nodes.Attribute, attribute)
922920
if (
923921
attribute.attrname != function_def.name
924922
or attribute.scope() == function_def # We ignore recursive calls
@@ -978,7 +976,6 @@ def _check_unused_private_variables(self, node: nodes.ClassDef) -> None:
978976

979977
def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
980978
for assign_attr in node.nodes_of_class(nodes.AssignAttr):
981-
assign_attr = cast(nodes.AssignAttr, assign_attr)
982979
if not is_attr_private(assign_attr.attrname) or not isinstance(
983980
assign_attr.expr, nodes.Name
984981
):
@@ -999,7 +996,6 @@ def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
999996
)
1000997

1001998
for attribute in node.nodes_of_class(nodes.Attribute):
1002-
attribute = cast(nodes.Attribute, attribute)
1003999
if attribute.attrname != assign_attr.attrname:
10041000
continue
10051001

pylint/checkers/refactoring/recommendation_checker.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
3-
from typing import Union, cast
3+
from typing import Union
44

55
import astroid
66
from astroid import nodes
@@ -128,17 +128,14 @@ def _check_use_maxsplit_arg(self, node: nodes.Call) -> None:
128128
# Check if loop present within the scope of the node
129129
scope = node.scope()
130130
for loop_node in scope.nodes_of_class((nodes.For, nodes.While)):
131-
loop_node = cast(nodes.NodeNG, loop_node)
132131
if not loop_node.parent_of(node):
133132
continue
134133

135134
# Check if var is mutated within loop (Assign/AugAssign)
136135
for assignment_node in loop_node.nodes_of_class(nodes.AugAssign):
137-
assignment_node = cast(nodes.AugAssign, assignment_node)
138136
if node.parent.slice.name == assignment_node.target.name:
139137
return
140138
for assignment_node in loop_node.nodes_of_class(nodes.Assign):
141-
assignment_node = cast(nodes.Assign, assignment_node)
142139
if node.parent.slice.name in [
143140
n.name for n in assignment_node.targets
144141
]:
@@ -216,7 +213,6 @@ def _check_consider_using_enumerate(self, node: nodes.For) -> None:
216213
# for body.
217214
for child in node.body:
218215
for subscript in child.nodes_of_class(nodes.Subscript):
219-
subscript = cast(nodes.Subscript, subscript)
220216
if not isinstance(subscript.value, expected_subscript_val_type):
221217
continue
222218

@@ -254,8 +250,6 @@ def _check_consider_using_dict_items(self, node: nodes.For) -> None:
254250
# for body.
255251
for child in node.body:
256252
for subscript in child.nodes_of_class(nodes.Subscript):
257-
subscript = cast(nodes.Subscript, subscript)
258-
259253
if not isinstance(subscript.value, (nodes.Name, nodes.Attribute)):
260254
continue
261255

@@ -304,8 +298,6 @@ def _check_consider_using_dict_items_comprehension(
304298

305299
for child in node.parent.get_children():
306300
for subscript in child.nodes_of_class(nodes.Subscript):
307-
subscript = cast(nodes.Subscript, subscript)
308-
309301
if not isinstance(subscript.value, (nodes.Name, nodes.Attribute)):
310302
continue
311303

pylint/checkers/refactoring/refactoring_checker.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import itertools
77
import tokenize
88
from functools import reduce
9-
from typing import Dict, Iterator, List, NamedTuple, Optional, Tuple, Union, cast
9+
from typing import Dict, Iterator, List, NamedTuple, Optional, Tuple, Union
1010

1111
import astroid
1212
from astroid import nodes
@@ -1862,8 +1862,6 @@ def _check_unnecessary_dict_index_lookup(
18621862
)
18631863
for child in children:
18641864
for subscript in child.nodes_of_class(nodes.Subscript):
1865-
subscript = cast(nodes.Subscript, subscript)
1866-
18671865
if not isinstance(subscript.value, (nodes.Name, nodes.Attribute)):
18681866
continue
18691867

0 commit comments

Comments
 (0)