Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Detect variables which may be undefined in some code paths #299

Closed

Description

microsoft/vscode-python#2958

Try to help people detect UnboundLocalError`NameError` situations like:

def example():
    if True:
        pass
    else:
        x = 42
    print(x * 2)

example()

or

def example():
    print(x * 2)
    x = 42

example()

(Make the above examples global-level statements and they become NameError.)

Activity

  1. jakebailey commented on Oct 22, 2018

    @jakebailey
    Member

    That second one is the same as #242, but the first of those examples is different as the analyzer will see that x is defined in the same scope and won't warn and is probably a further enhancement.

    With #298:

    image

  2. MikhailArkhipov commented on Oct 22, 2018

    @MikhailArkhipov

    I'd change message to 'variable is possibly undeclared in some code path'

  3. MikhailArkhipov commented on Oct 24, 2018

    @MikhailArkhipov

    Jake Bailey (@jakebailey) - wrt the message wording

  4. changed the title [-]Detect variables referenced before assignment[/-] [+]Change unknown variable message[/+] on Oct 24, 2018
  5. qubitron commented on Oct 24, 2018

    @qubitron

    Need to move messages to resources
    Remove (analysis), (parser) etc.

  6. changed the title [-]Change unknown variable message[/-] [+]Detect variables which may be undefined in some code paths[/+] on Oct 24, 2018
  7. jakebailey commented on Oct 30, 2018

    @jakebailey
    Member

    I think that first one could actually just be solved by #313 (dataflow analysis recognizing a code path without the variable being defined), so I'll do the naming fixes then close this when those are in.

  8. added a commit that references this issue on Oct 30, 2018
    d003732
  9. added a commit that references this issue on Nov 1, 2019
    67c98b9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions