Skip to content

Commit 60e8382

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

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

mypy/checker.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
)
3333
from mypy.checkpattern import PatternChecker
3434
from mypy.constraints import SUPERTYPE_OF
35+
from mypy.disallow_str_iteration_state import (
36+
STR_ITERATION_PROTOCOL_BASES,
37+
disallow_str_iteration_state,
38+
)
3539
from mypy.erasetype import erase_type, erase_typevars, remove_instance_last_known_values
3640
from mypy.errorcodes import TYPE_VAR, UNUSED_AWAITABLE, UNUSED_COROUTINE, ErrorCode
3741
from mypy.errors import (
@@ -155,10 +159,6 @@
155159
from mypy.semanal_enum import ENUM_BASES, ENUM_SPECIAL_PROPS
156160
from mypy.semanal_shared import SemanticAnalyzerCoreInterface
157161
from mypy.sharedparse import BINARY_MAGIC_METHODS
158-
from mypy.disallow_str_iteration_state import (
159-
STR_ITERATION_PROTOCOL_BASES,
160-
disallow_str_iteration_state,
161-
)
162162
from mypy.state import state
163163
from mypy.subtypes import (
164164
find_member,
@@ -8003,13 +8003,17 @@ def expand_isinstance_type_ranges(self, types: list[TypeRange]) -> list[TypeRang
80038003

80048004
def _is_str_iteration_protocol_for_narrowing(self, typ: Type) -> bool:
80058005
proper = get_proper_type(typ)
8006-
return isinstance(proper, Instance) and proper.type.fullname in STR_ITERATION_PROTOCOL_BASES
8006+
return (
8007+
isinstance(proper, Instance) and proper.type.fullname in STR_ITERATION_PROTOCOL_BASES
8008+
)
80078009

80088010
def expand_narrowed_type(self, typ: Type) -> Type:
80098011
if disallow_str_iteration_state.disallow_str_iteration:
80108012
proper = get_proper_type(typ)
80118013
if isinstance(proper, UnionType):
8012-
return make_simplified_union([self.expand_narrowed_type(item) for item in proper.items])
8014+
return make_simplified_union(
8015+
[self.expand_narrowed_type(item) for item in proper.items]
8016+
)
80138017
if self._is_str_iteration_protocol_for_narrowing(proper):
80148018
return make_simplified_union([typ, self.named_type("builtins.str")])
80158019
return typ

mypy/disallow_str_iteration_state.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import annotations
2-
from mypy.types import Instance
32

43
from collections.abc import Iterator
54
from contextlib import contextmanager
65
from typing import Final
76

7+
from mypy.types import Instance
8+
89

910
class DisallowStrIterationState:
1011
# Wrap this in a class since it's faster that using a module-level attribute.

mypy/join.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
from typing import overload
77

88
import mypy.typeops
9-
from mypy.expandtype import expand_type
10-
from mypy.maptype import map_instance_to_supertype
11-
from mypy.nodes import CONTRAVARIANT, COVARIANT, INVARIANT, VARIANCE_NOT_READY, TypeInfo
129
from mypy.disallow_str_iteration_state import (
13-
disallow_str_iteration_state,
1410
STR_ITERATION_PROTOCOL_BASES,
11+
disallow_str_iteration_state,
1512
)
13+
from mypy.expandtype import expand_type
14+
from mypy.maptype import map_instance_to_supertype
15+
from mypy.nodes import CONTRAVARIANT, COVARIANT, INVARIANT, VARIANCE_NOT_READY, TypeInfo
1616
from mypy.state import state
1717
from mypy.subtypes import (
1818
SubtypeContext,

mypy/meet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
from collections.abc import Callable
44

55
from mypy import join
6-
from mypy.erasetype import erase_type
7-
from mypy.maptype import map_instance_to_supertype
86
from mypy.disallow_str_iteration_state import (
97
disallow_str_iteration_state,
108
is_subtype_relation_ignored_to_disallow_str_iteration,
119
)
10+
from mypy.erasetype import erase_type
11+
from mypy.maptype import map_instance_to_supertype
1212
from mypy.state import state
1313
from mypy.subtypes import (
1414
are_parameters_compatible,

mypy/subtypes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import mypy.constraints
99
import mypy.typeops
1010
from mypy.checker_state import checker_state
11+
from mypy.disallow_str_iteration_state import (
12+
disallow_str_iteration_state,
13+
is_subtype_relation_ignored_to_disallow_str_iteration,
14+
)
1115
from mypy.erasetype import erase_type
1216
from mypy.expandtype import (
1317
expand_self_type,
@@ -34,10 +38,6 @@
3438
Var,
3539
)
3640
from mypy.options import Options
37-
from mypy.disallow_str_iteration_state import (
38-
disallow_str_iteration_state,
39-
is_subtype_relation_ignored_to_disallow_str_iteration,
40-
)
4141
from mypy.state import state
4242
from mypy.types import (
4343
MYPYC_NATIVE_INT_NAMES,

0 commit comments

Comments
 (0)