Skip to content

(🐞) Inconsistent reachability depending if module level or not #12409

Open
@KotlinIsland

Description

@KotlinIsland

Really strange behavior here, when this statement is on the module level it creates a silently unreachable branch, but when in a scope it doesn't create unreachable

import sys


def foo() -> None:
    assert sys.platform == "AMONGUS"
    a # error, reachable ❌

cond: bool
if cond:
    assert sys.platform == "AMONGUS"
    a # error, reachable ❌

assert sys.platform == "AMONGUS"
a  # no error, silent unreachable ✅

playground

Related #11438
Related #11361

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-reachabilityDetecting unreachable code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions