Skip to content

Commit ac03c88

Browse files
committed
Address PR review
1 parent bc8cb90 commit ac03c88

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

mypy/checkexpr.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4296,12 +4296,8 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
42964296
elif e.op == "or":
42974297
left_map, right_map = self.chk.find_isinstance_check(e.left)
42984298

4299-
left_impossible = left_map is None or any(
4300-
isinstance(get_proper_type(v), UninhabitedType) for v in left_map.values()
4301-
)
4302-
right_impossible = right_map is None or any(
4303-
isinstance(get_proper_type(v), UninhabitedType) for v in right_map.values()
4304-
)
4299+
left_impossible = is_impossible_map(left_map)
4300+
right_impossible = is_impossible_map(right_map)
43054301

43064302
# If left_map is None then we know mypy considers the left expression
43074303
# to be redundant.
@@ -5835,13 +5831,9 @@ def check_for_comp(self, e: GeneratorExpr | DictionaryComprehension) -> None:
58355831
self.chk.push_type_map(true_map)
58365832

58375833
if codes.REDUNDANT_EXPR in self.chk.options.enabled_error_codes:
5838-
if true_map is None or any(
5839-
isinstance(get_proper_type(t), UninhabitedType) for t in true_map.values()
5840-
):
5834+
if is_impossible_map(true_map):
58415835
self.msg.redundant_condition_in_comprehension(False, condition)
5842-
elif false_map is None or any(
5843-
isinstance(get_proper_type(t), UninhabitedType) for t in false_map.values()
5844-
):
5836+
elif is_impossible_map(false_map):
58455837
self.msg.redundant_condition_in_comprehension(True, condition)
58465838

58475839
def visit_conditional_expr(self, e: ConditionalExpr, allow_none_return: bool = False) -> Type:
@@ -5852,13 +5844,9 @@ def visit_conditional_expr(self, e: ConditionalExpr, allow_none_return: bool = F
58525844
# but only for the current expression
58535845
if_map, else_map = self.chk.find_isinstance_check(e.cond)
58545846
if codes.REDUNDANT_EXPR in self.chk.options.enabled_error_codes:
5855-
if if_map is None or any(
5856-
isinstance(get_proper_type(t), UninhabitedType) for t in if_map.values()
5857-
):
5847+
if is_impossible_map(if_map):
58585848
self.msg.redundant_condition_in_if(False, e.cond)
5859-
elif else_map is None or any(
5860-
isinstance(get_proper_type(t), UninhabitedType) for t in else_map.values()
5861-
):
5849+
elif is_impossible_map(else_map):
58625850
self.msg.redundant_condition_in_if(True, e.cond)
58635851

58645852
if_type = self.analyze_cond_branch(
@@ -5946,9 +5934,7 @@ def analyze_cond_branch(
59465934
with self.chk.binder.frame_context(can_skip=True, fall_through=0):
59475935
self.chk.push_type_map(map)
59485936

5949-
if map is None or any(
5950-
isinstance(get_proper_type(t), UninhabitedType) for t in map.values()
5951-
):
5937+
if is_impossible_map(map):
59525938
# We still need to type check node, in case we want to
59535939
# process it for isinstance checks later. Since the branch was
59545940
# determined to be unreachable, any errors should be suppressed.
@@ -6757,3 +6743,14 @@ def is_type_type_context(context: Type | None) -> bool:
67576743
if isinstance(context, UnionType):
67586744
return any(is_type_type_context(item) for item in context.items)
67596745
return False
6746+
6747+
6748+
def is_impossible_map(map: mypy.checker.TypeMap) -> bool:
6749+
if map is None:
6750+
return True
6751+
6752+
for v in map.values():
6753+
if isinstance(get_proper_type(v), UninhabitedType):
6754+
return True
6755+
6756+
return False

mypyc/ir/pprint.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,8 @@ def visit_call_c(self, op: CallC) -> str:
221221

222222
def visit_primitive_op(self, op: PrimitiveOp) -> str:
223223
args = []
224-
arg_index = 0
225-
# type_arg_index = 0
226-
for arg_type in zip(op.desc.arg_types):
227-
if arg_type:
228-
args.append(self.format("%r", op.args[arg_index]))
229-
arg_index += 1
230-
else:
231-
assert False
232-
# assert op.type_args
233-
# args.append(self.format("%r", op.type_args[type_arg_index]))
234-
# type_arg_index += 1
224+
for arg in op.args:
225+
args.append(self.format("%r", arg))
235226

236227
args_str = ", ".join(args)
237228
if op.is_void:

0 commit comments

Comments
 (0)