Skip to content

weird reportUnboundVariable behaviour #3041

@klement

Description

@klement

So this construct caught my eye:

  def x():
      y = True
      if y:
          a = 1
      if y:
>>        print(a)
                 "a" is possibly unbound
                 [Pyright: reportUnboundVariable]
                 ────────────────────────────────────────────────────────────────────
                 https://github.com/microsoft/pyright/blob/main/docs/configuration.md

I don't think there is a way how a could be unbound ...

curiously, it also complains for x

  def x():
      y = True
      if y:
          x = 1
      if y:
>>        print(x)
                 "x" is possibly unbound
                 [Pyright: reportUnboundVariable]
                 ────────────────────────────────────────────────────────────────────
                 https://github.com/microsoft/pyright/blob/main/docs/configuration.md

but in this case x is surely at least the function itself, yes?

changing the variable name makes it see that x can be the function itself:

  def x():
      y = True
      if y:
>>        a = 1
      if y:
          print(x)

there is now warning "a" is not accessed, but it no longer complains about x being possibly unbound

Metadata

Metadata

Assignees

No one assigned

    Labels

    as designedNot a bug, working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions