Skip to content

[partially defined] Doesn't catch usage within an if statement #14124

Closed

Description

@hauntsaninja

I'd expect an error in the following when using --enable-error-code partially-defined:

def bar(x: int) -> None: ...

def foo(cond: bool) -> None:
    if cond:
        a = 5
    else:
        bar(a)
    # print(a + 1)

Note that we get an error on the print statement if we uncomment it.

cc @ilinum

Activity

  1. ilinum commented on Nov 21, 2022

    @ilinum
    Collaborator

    I think this is part of general type of errors of the form that are currently not detected by mypy at all:

    def foo() -> None:
        x = y
        y: int = 1

    @ilevkivskyi suggested recently that we could modify the partially-defined check to detect variables that are used before definition. I believe this should be possible.

    Let's use this issue to track this request.

  2. added a commit that references this issue on Nov 22, 2022
    f656efc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions