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

Instance variable with same name as class erroneously flagged as unbound #175

Closed
Godsmith opened this issue Jul 26, 2020 · 3 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

@Godsmith
Copy link

Environment data

  • Language Server version: 2020.7.3
  • OS and version: Windows 10 1909
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8

Expected behaviour

When I have a module with the following code:

class bar:
    pass


class Foo:
    def __init__(self, bar_: bar) -> None:
        self.bar = "hello"

no problems shall be listed.

Actual behaviour

A problem appears in the Problems tab, and squiggly lines are shown under the type of the bar_ argument:

"bar" is unbound Pylance (reportUnboundVariable)

Logs

[BG] analyzing: c:\Users\filip\workspace\timereporter\timereporter\datetest.py (5ms)
[FG] parsing: c:\Users\filip\workspace\timereporter\timereporter\datetest.py (0ms)
[FG] binding: c:\Users\filip\workspace\timereporter\timereporter\datetest.py (0ms)
[BG] analyzing: c:\Users\filip\workspace\timereporter\timereporter\datetest.py ...
[BG]   parsing: c:\Users\filip\workspace\timereporter\timereporter\datetest.py (4ms)
[BG]   binding: c:\Users\filip\workspace\timereporter\timereporter\datetest.py (1ms)
[BG]   checking: c:\Users\filip\workspace\timereporter\timereporter\datetest.py (27ms)
[BG] analyzing: c:\Users\filip\workspace\timereporter\timereporter\datetest.py (33ms)
[FG] parsing: c:\Users\filip\workspace\timereporter\timereporter\datetest.py (1ms)
[FG] binding: c:\Users\filip\workspace\timereporter\timereporter\datetest.py (0ms)
[BG] analyzing: c:\Users\filip\workspace\timereporter\timereporter\datetest.py ...
[BG]   parsing: c:\Users\filip\workspace\timereporter\timereporter\datetest.py (1ms)
[BG]   binding: c:\Users\filip\workspace\timereporter\timereporter\datetest.py (0ms)
[BG]   checking: c:\Users\filip\workspace\timereporter\timereporter\datetest.py (8ms)
[BG] analyzing: c:\Users\filip\workspace\timereporter\timereporter\datetest.py (9ms)

Code Snippet / Additional information

One might think it would be rare that you would have a variable with the same name as a class, however, some packages like datetime has lowercase class names. In fact, I found this bug when I tried to name a variable date while I had imported the date class from datetime.

@erictraut
Copy link
Contributor

Thanks for the bug report. I just introduced a fix for this problem. It will be addressed in the next version 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 labels Jul 26, 2020
@CatNofishing
Copy link

Good!

@jakebailey
Copy link
Member

This issue has been fixed in version 2020.7.4, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202074-29-july-2020

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

4 participants