Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2762,7 +2762,7 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
# the analysis from the semanal phase below. We assume that nodes
# marked as unreachable during semantic analysis were done so intentionally.
# So, we shouldn't report an error.
if self.chk.options.warn_unreachable:
if self.chk.should_report_unreachable_issues():
if right_map is None:
self.msg.unreachable_right_operand(e.op, e.right)

Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/check-unreachable-code.test
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ from typing import TypeVar, Generic

T1 = TypeVar('T1', bound=int)
T2 = TypeVar('T2', int, str)
T3 = TypeVar('T3', None, str)

def test1(x: T1) -> T1:
if isinstance(x, int):
Expand Down Expand Up @@ -961,6 +962,19 @@ class Test3(Generic[T2]):
# Same issue as above
reveal_type(self.x)


class Test4(Generic[T3]):
def __init__(self, x: T3):
# https://github.com/python/mypy/issues/9456
# On TypeVars with value restrictions, we currently have no way
# of checking a statement for all the type expansions.
# Thus unreachable warnings are disabled
if x and False:
pass
# This test should fail after this limitation is removed.
if False and x:
pass

[builtins fixtures/isinstancelist.pyi]

[case testUnreachableFlagContextManagersNoSuppress]
Expand Down