Skip to content

Erroneous unbound-name when using NoReturn #2406

Description

@MarcoGorelli

Describe the Bug

When running the code below I get

ERROR `node` may be uninitialized [unbound-name]

Pyright handles it fine

from typing import NoReturn

def foo() -> NoReturn:
    raise ValueError('')

def main(resolve: bool) -> None:
    try:
        node = 1
    except Exception as exc:
        foo()
    if resolve:
        try:
            node = 2
        except Exception:
            foo()
    print(node)

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN0A5XACUYDAK6V0AHRlYYYOmFy4AFAEo6AWgB8gkWMnpEsumbqVUEODDoA1VFHEwAopWqVVAci-rZszAU6Git0VUp4XCgANxhEOjwozV19dDjTcwZKUhN0c3y6dFxAugBeOgBGDLMYfABjGGJ%2BF3rGhghcPNQ4Olq63ILzZTU-PPMIRQi4KNiBwcZsufnzIpLygCZqgr62uhaGpo7jLeXhjS3iSlYGVVWYUZAAGhBxdqg4EnJEEABiOgBVN4QJhKcToOrtTpwfzyRTKSghBgAfXQ4ho2Bgnnw8WuyT0cCySwshikSmkIAEaIxlHiwHwAF9ybIniAyBEwFBSIQGLQoBQ-gAFUjszl0NBYPD4Oh1TqQNiSVCQ9CEWR-ADKMFsAAsGAxiHBEAB6Q1shScwi8NiGmDoQ2YXB1OCGmXoOUKpWGpS8OioaJWKCobCwaWyiDyyxKui4Q5QlXoMgMLWdLSxShwI5lOjkgDMhAqmxAzPpz1QEIgsQAYtAYBRxTgCJ8QPSgA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    scoping-control-flowissues related to scoping and control flow

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions