Skip to content

Commit 2ea2c81

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

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

mypy/checker.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@
241241
from mypy.typevars import fill_typevars, fill_typevars_with_any, has_no_typevars
242242
from mypy.util import is_dunder, is_sunder
243243
from mypy.visitor import NodeVisitor
244-
from mypy.types import LiteralType
245244

246245
T = TypeVar("T")
247246

@@ -6581,18 +6580,18 @@ def comparison_type_narrowing_helper(self, node: ComparisonExpr) -> tuple[TypeMa
65816580

65826581
if left_index in narrowable_operand_index_to_hash:
65836582
# We only try and narrow away 'None' for now
6584-
if is_overlapping_none(item_type):
6585-
collection_item_type = get_proper_type(builtin_item_type(iterable_type))
6586-
if (
6587-
collection_item_type is not None
6588-
and not is_overlapping_none(collection_item_type)
6589-
and not (
6590-
isinstance(collection_item_type, Instance)
6591-
and collection_item_type.type.fullname == "builtins.object"
6592-
)
6593-
and is_overlapping_erased_types(item_type, collection_item_type)
6594-
):
6595-
if_map[operands[left_index]] = remove_optional(item_type)
6583+
if is_overlapping_none(item_type):
6584+
collection_item_type = get_proper_type(builtin_item_type(iterable_type))
6585+
if (
6586+
collection_item_type is not None
6587+
and not is_overlapping_none(collection_item_type)
6588+
and not (
6589+
isinstance(collection_item_type, Instance)
6590+
and collection_item_type.type.fullname == "builtins.object"
6591+
)
6592+
and is_overlapping_erased_types(item_type, collection_item_type)
6593+
):
6594+
if_map[operands[left_index]] = remove_optional(item_type)
65966595
if_map[operands[left_index]] = remove_optional(item_type)
65976596
literal_types = []
65986597
if isinstance(get_proper_type(iterable_type), TupleType):
@@ -6603,7 +6602,10 @@ def comparison_type_narrowing_helper(self, node: ComparisonExpr) -> tuple[TypeMa
66036602

66046603
if item_type.type.is_enum:
66056604
# Enum values in tuples are represented as Instance types, not LiteralType
6606-
if hasattr(item_type, 'last_known_value') and item_type.last_known_value:
6605+
if (
6606+
hasattr(item_type, "last_known_value")
6607+
and item_type.last_known_value
6608+
):
66076609
# Use the existing literal representation
66086610
literal_types.append(item_type.last_known_value)
66096611
else:

0 commit comments

Comments
 (0)