Skip to content

Commit b641ed4

Browse files
committed
Smooth out edges
1 parent 0f41d33 commit b641ed4

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

mypy/checkexpr.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,12 +1669,6 @@ def check_callable_call(
16691669
if isinstance(callable_node, RefExpr) and callable_node.fullname in ENUM_BASES:
16701670
# An Enum() call that failed SemanticAnalyzerPass2.check_enum_call().
16711671
return callee.ret_type, callee
1672-
if (
1673-
isinstance(callable_node, RefExpr)
1674-
and callable_node.fullname in ("typing.assert_never", "typing_extensions.assert_never")
1675-
and self.chk.binder.is_unreachable()
1676-
):
1677-
return callee.ret_type, callee
16781672

16791673
if (
16801674
callee.is_type_obj()
@@ -1804,9 +1798,20 @@ def check_callable_call(
18041798
callable_name,
18051799
)
18061800

1807-
self.check_argument_types(
1808-
arg_types, arg_kinds, args, callee, formal_to_actual, context, object_type=object_type
1809-
)
1801+
if not (
1802+
isinstance(callable_node, RefExpr)
1803+
and callable_node.fullname in ("typing.assert_never", "typing_extensions.assert_never")
1804+
and self.chk.binder.is_unreachable()
1805+
):
1806+
self.check_argument_types(
1807+
arg_types,
1808+
arg_kinds,
1809+
args,
1810+
callee,
1811+
formal_to_actual,
1812+
context,
1813+
object_type=object_type,
1814+
)
18101815

18111816
if (
18121817
callee.is_type_obj()

test-data/unit/check-typeis.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,10 @@ def g(x: object) -> None: ...
454454
def test(x: List[Any]) -> None:
455455
if not(f(x) or isinstance(x, A)):
456456
return
457+
457458
g(reveal_type(x)) # N: Revealed type is "builtins.list[Any]"
459+
# explanation: `if f(x): ...` is assumed always true!
460+
# so there's no narrowing here.
458461
[builtins fixtures/tuple.pyi]
459462

460463
[case testTypeIsMultipleCondition]

test-data/unit/check-unreachable-code.test

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ if False:
910910
# Ignore obvious type errors
911911
assert_never(expect_str(x)) # E: Argument 1 to "assert_never" has incompatible type "str"; expected "Never" \
912912
# E: Argument 1 to "expect_str" has incompatible type "int"; expected "str"
913-
typing_assert_never(expect_str(x))
913+
typing_assert_never(expect_str(x)) # E: Argument 1 to "expect_str" has incompatible type "int"; expected "str"
914914
reveal_type(x) # E: Statement is unreachable \
915915
# N: Revealed type is "builtins.int"
916916

@@ -1364,6 +1364,9 @@ def test_untyped_fn(obj):
13641364
obj.update(prop=False)
13651365
obj.reload()
13661366

1367+
reveal_type(obj.prop) # N: Revealed type is "Any" \
1368+
# N: 'reveal_type' always outputs 'Any' in unchecked functions
1369+
13671370
assert obj.prop is False
13681371
reveal_type(obj.prop) # N: Revealed type is "Any" \
13691372
# N: 'reveal_type' always outputs 'Any' in unchecked functions

0 commit comments

Comments
 (0)