Skip to content
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

Remove most typing.cast() calls #4995

Merged
merged 3 commits into from Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions pylint/checkers/classes.py
Expand Up @@ -47,7 +47,7 @@
"""
import collections
from itertools import chain, zip_longest
from typing import List, Pattern, cast
from typing import List, Pattern

import astroid
from astroid import nodes
Expand Down Expand Up @@ -907,7 +907,6 @@ def leave_classdef(self, node: nodes.ClassDef) -> None:

def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
for function_def in node.nodes_of_class(nodes.FunctionDef):
function_def = cast(nodes.FunctionDef, function_def)
if not is_attr_private(function_def.name):
continue
parent_scope = function_def.parent.scope()
Expand All @@ -918,7 +917,6 @@ def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
):
continue
for attribute in node.nodes_of_class(nodes.Attribute):
attribute = cast(nodes.Attribute, attribute)
if (
attribute.attrname != function_def.name
or attribute.scope() == function_def # We ignore recursive calls
Expand Down Expand Up @@ -978,7 +976,6 @@ def _check_unused_private_variables(self, node: nodes.ClassDef) -> None:

def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
for assign_attr in node.nodes_of_class(nodes.AssignAttr):
assign_attr = cast(nodes.AssignAttr, assign_attr)
if not is_attr_private(assign_attr.attrname) or not isinstance(
assign_attr.expr, nodes.Name
):
Expand All @@ -999,7 +996,6 @@ def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
)

for attribute in node.nodes_of_class(nodes.Attribute):
attribute = cast(nodes.Attribute, attribute)
if attribute.attrname != assign_attr.attrname:
continue

Expand Down
7 changes: 0 additions & 7 deletions pylint/checkers/refactoring/recommendation_checker.py
Expand Up @@ -127,11 +127,9 @@ def _check_use_maxsplit_arg(self, node: nodes.Call) -> None:

# Check if var is mutated within loop (Assign/AugAssign)
for assignment_node in loop_node.nodes_of_class(nodes.AugAssign):
assignment_node = cast(nodes.AugAssign, assignment_node)
if node.parent.slice.name == assignment_node.target.name:
return
for assignment_node in loop_node.nodes_of_class(nodes.Assign):
assignment_node = cast(nodes.Assign, assignment_node)
if node.parent.slice.name in [
n.name for n in assignment_node.targets
]:
Expand Down Expand Up @@ -209,7 +207,6 @@ def _check_consider_using_enumerate(self, node: nodes.For) -> None:
# for body.
for child in node.body:
for subscript in child.nodes_of_class(nodes.Subscript):
subscript = cast(nodes.Subscript, subscript)
if not isinstance(subscript.value, expected_subscript_val_type):
continue

Expand Down Expand Up @@ -247,8 +244,6 @@ def _check_consider_using_dict_items(self, node: nodes.For) -> None:
# for body.
for child in node.body:
for subscript in child.nodes_of_class(nodes.Subscript):
subscript = cast(nodes.Subscript, subscript)

if not isinstance(subscript.value, (nodes.Name, nodes.Attribute)):
continue

Expand Down Expand Up @@ -297,8 +292,6 @@ def _check_consider_using_dict_items_comprehension(

for child in node.parent.get_children():
for subscript in child.nodes_of_class(nodes.Subscript):
subscript = cast(nodes.Subscript, subscript)

if not isinstance(subscript.value, (nodes.Name, nodes.Attribute)):
continue

Expand Down
4 changes: 1 addition & 3 deletions pylint/checkers/refactoring/refactoring_checker.py
Expand Up @@ -6,7 +6,7 @@
import itertools
import tokenize
from functools import reduce
from typing import Dict, Iterator, List, NamedTuple, Optional, Tuple, Union, cast
from typing import Dict, Iterator, List, NamedTuple, Optional, Tuple, Union

import astroid
from astroid import nodes
Expand Down Expand Up @@ -1862,8 +1862,6 @@ def _check_unnecessary_dict_index_lookup(
)
for child in children:
for subscript in child.nodes_of_class(nodes.Subscript):
subscript = cast(nodes.Subscript, subscript)

if not isinstance(subscript.value, (nodes.Name, nodes.Attribute)):
continue

Expand Down