|
32 | 32 | ) |
33 | 33 | from mypy.checkpattern import PatternChecker |
34 | 34 | 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 | +) |
35 | 39 | from mypy.erasetype import erase_type, erase_typevars, remove_instance_last_known_values |
36 | 40 | from mypy.errorcodes import TYPE_VAR, UNUSED_AWAITABLE, UNUSED_COROUTINE, ErrorCode |
37 | 41 | from mypy.errors import ( |
|
155 | 159 | from mypy.semanal_enum import ENUM_BASES, ENUM_SPECIAL_PROPS |
156 | 160 | from mypy.semanal_shared import SemanticAnalyzerCoreInterface |
157 | 161 | 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 | | -) |
162 | 162 | from mypy.state import state |
163 | 163 | from mypy.subtypes import ( |
164 | 164 | find_member, |
@@ -8003,13 +8003,17 @@ def expand_isinstance_type_ranges(self, types: list[TypeRange]) -> list[TypeRang |
8003 | 8003 |
|
8004 | 8004 | def _is_str_iteration_protocol_for_narrowing(self, typ: Type) -> bool: |
8005 | 8005 | 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 | + ) |
8007 | 8009 |
|
8008 | 8010 | def expand_narrowed_type(self, typ: Type) -> Type: |
8009 | 8011 | if disallow_str_iteration_state.disallow_str_iteration: |
8010 | 8012 | proper = get_proper_type(typ) |
8011 | 8013 | 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 | + ) |
8013 | 8017 | if self._is_str_iteration_protocol_for_narrowing(proper): |
8014 | 8018 | return make_simplified_union([typ, self.named_type("builtins.str")]) |
8015 | 8019 | return typ |
|
0 commit comments