Skip to content

Commit a8f7922

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 5635724 commit a8f7922

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

mypy/checkexpr.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4497,7 +4497,11 @@ def min_tuple_length(self, left: TupleType) -> int:
44974497

44984498
def static_index_range_check(self, left_type: Type, e: IndexExpr, index: Expression):
44994499
if isinstance(left_type, Instance) and left_type.type.fullname in (
4500-
"builtins.list", "builtins.set", "builtins.dict", "builtins.str", "builtins.bytes"
4500+
"builtins.list",
4501+
"builtins.set",
4502+
"builtins.dict",
4503+
"builtins.str",
4504+
"builtins.bytes",
45014505
):
45024506
idx_val = None
45034507
# Try to extract integer literal index

mypy/errorcodes.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,7 @@ def __hash__(self) -> int:
322322
default_enabled=False,
323323
)
324324

325-
INDEX_RANGE = ErrorCode(
326-
"index-range",
327-
"index out of statically known range",
328-
"Index Range",
329-
True,
330-
)
325+
INDEX_RANGE = ErrorCode("index-range", "index out of statically known range", "Index Range", True)
331326

332327
# This copy will not include any error codes defined later in the plugins.
333328
mypy_error_codes = error_codes.copy()

mypy/exprlength.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,38 @@
55
"""
66

77
from typing import List, Optional, Tuple
8+
89
from mypy.nodes import (
10+
ARG_POS,
11+
AssignmentStmt,
12+
Block,
13+
BytesExpr,
14+
CallExpr,
15+
ClassDef,
16+
DictExpr,
917
Expression,
1018
ExpressionStmt,
1119
ForStmt,
20+
FuncDef,
1221
GeneratorExpr,
22+
GlobalDecl,
1323
IfStmt,
1424
ListComprehension,
1525
ListExpr,
16-
TupleExpr,
17-
SetExpr,
18-
WhileStmt,
19-
DictExpr,
2026
MemberExpr,
21-
StrExpr,
22-
StarExpr,
23-
BytesExpr,
24-
CallExpr,
2527
NameExpr,
28+
NonlocalDecl,
29+
OverloadedFuncDef,
30+
SetExpr,
31+
StarExpr,
32+
StrExpr,
2633
TryStmt,
27-
Block,
28-
AssignmentStmt,
34+
TupleExpr,
35+
WhileStmt,
36+
WithStmt,
2937
is_IntExpr_list,
3038
)
31-
from mypy.nodes import WithStmt, FuncDef, OverloadedFuncDef, ClassDef, GlobalDecl, NonlocalDecl
32-
from mypy.nodes import ARG_POS
39+
3340

3441
def get_static_expr_length(expr: Expression, context: Optional[Block] = None) -> Optional[int]:
3542
"""Try to statically determine the length of an expression.
@@ -100,7 +107,19 @@ def get_static_expr_length(expr: Expression, context: Optional[Block] = None) ->
100107

101108
# Iterate thru all statements in the block
102109
for stmt in context.body:
103-
if isinstance(stmt, (IfStmt, ForStmt, WhileStmt, TryStmt, WithStmt, FuncDef, OverloadedFuncDef, ClassDef)):
110+
if isinstance(
111+
stmt,
112+
(
113+
IfStmt,
114+
ForStmt,
115+
WhileStmt,
116+
TryStmt,
117+
WithStmt,
118+
FuncDef,
119+
OverloadedFuncDef,
120+
ClassDef,
121+
),
122+
):
104123
# These statements complicate things and render the whole block useless
105124
return None
106125
elif isinstance(stmt, (GlobalDecl, NonlocalDecl)) and expr.name in stmt.names:

mypy/message_registry.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,5 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
369369
)
370370

371371
SEQUENCE_INDEX_OUT_OF_RANGE = ErrorMessage(
372-
"Sequence index out of range: {name!r} only has {length} items",
373-
code=codes.INDEX_RANGE,
372+
"Sequence index out of range: {name!r} only has {length} items", code=codes.INDEX_RANGE
374373
)

0 commit comments

Comments
 (0)