Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Unbound variable' error for class inheritance with global keyword #950

Closed
abelcheung opened this issue Feb 14, 2021 · 2 comments
Closed
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@abelcheung
Copy link

Environment data

  • Language Server version: 2021.2.2 (possibly irrelevant, all versions since 2021.1.1 known to have same issue)
  • OS and version: XXX
  • Python version (& distribution if applicable, e.g. Anaconda): XXX

Description of issue

I use a somewhat... er... non-standard template for some files, intended to avoid any re-exporting of imported modules (see code sample below). It works fine so far until I try to include class inheritance into the game. Pylance would complain about all superclasses used this way, although the code itself runs fine.

Just wondering, if this is a false positive or a deliberate warning.

(As a side note, I'm aware that the standard way is to just mark everything as private with underscore prefix)

Screenshot

圖片

Code sample

# stub here
class A: ...
class B(A): ...
class C(B): ...

def _init():

    # most imports done here
    global A, B, C

    class A:
        def __init__(self) -> None:
            print('A')
    class B(A): pass
    class C(B): pass

_init()
del _init

c = C()
@erictraut
Copy link
Contributor

Thanks for reporting the issue. This will be fixed in the next release of pylance.

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Feb 15, 2021
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.2.3, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202123-17-february-2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants