|
155 | 155 | from mypy.semanal_enum import ENUM_BASES, ENUM_SPECIAL_PROPS |
156 | 156 | from mypy.semanal_shared import SemanticAnalyzerCoreInterface |
157 | 157 | from mypy.sharedparse import BINARY_MAGIC_METHODS |
| 158 | +from mypy.disallow_str_iteration_state import disallow_str_iteration_state |
158 | 159 | from mypy.state import state |
159 | 160 | from mypy.subtypes import ( |
160 | 161 | find_member, |
@@ -514,7 +515,11 @@ def check_first_pass(self) -> None: |
514 | 515 | Deferred functions will be processed by check_second_pass(). |
515 | 516 | """ |
516 | 517 | self.recurse_into_functions = True |
517 | | - with state.strict_optional_set(self.options.strict_optional), checker_state.set(self): |
| 518 | + with ( |
| 519 | + state.strict_optional_set(self.options.strict_optional), |
| 520 | + disallow_str_iteration_state.set(self.options.disallow_str_iteration), |
| 521 | + checker_state.set(self), |
| 522 | + ): |
518 | 523 | self.errors.set_file( |
519 | 524 | self.path, self.tree.fullname, scope=self.tscope, options=self.options |
520 | 525 | ) |
@@ -559,7 +564,11 @@ def check_second_pass( |
559 | 564 | """ |
560 | 565 | self.allow_constructor_cache = allow_constructor_cache |
561 | 566 | self.recurse_into_functions = True |
562 | | - with state.strict_optional_set(self.options.strict_optional), checker_state.set(self): |
| 567 | + with ( |
| 568 | + state.strict_optional_set(self.options.strict_optional), |
| 569 | + disallow_str_iteration_state.set(self.options.disallow_str_iteration), |
| 570 | + checker_state.set(self), |
| 571 | + ): |
563 | 572 | if not todo and not self.deferred_nodes: |
564 | 573 | return False |
565 | 574 | self.errors.set_file( |
@@ -5382,7 +5391,9 @@ def analyze_iterable_item_type_without_expression( |
5382 | 5391 | iterable: Type |
5383 | 5392 | iterable = get_proper_type(type) |
5384 | 5393 |
|
5385 | | - if self.options.disallow_str_iteration and self.is_str_iteration_type(iterable): |
| 5394 | + if disallow_str_iteration_state.disallow_str_iteration and self.is_str_iteration_type( |
| 5395 | + iterable |
| 5396 | + ): |
5386 | 5397 | self.msg.str_iteration_disallowed(context, iterable) |
5387 | 5398 |
|
5388 | 5399 | iterator = echk.check_method_call_by_name("__iter__", iterable, [], [], context)[0] |
|
0 commit comments