Skip to content

Avoid false positive "possibly unbound" #4087

@108anup

Description

@108anup

When variables are conditionally declared, then pyright may show "possibly unbound" error, even though ideally it should be able to infer that the variable won't be unbound.

DEFINE_X = True
if(DEFINE_X):
  x = 3

# ...
# Code that does not touch DEFINE_X
# ...

if(DEFINE_X):
  y = x + 3 # This line is highlighted as "x possibly unbound"
  # There is enough information in the code to ensure that
  # x is not unbound at this time. Perhaps such false positive
  # error messages can be avoided?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions