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

"Undefined variable" error while importing type annotated variables from python file #629

Closed
JaPyR opened this issue Mar 30, 2022 · 5 comments
Labels
bug Something isn't working robotframework-ls

Comments

@JaPyR
Copy link

JaPyR commented Mar 30, 2022

Describe the bug
I am getting "Undefined variable" error while importing type annotated variable from python file.
I've noticed in 0.43.0 (also 0.43.2) but in 0.42.0 works fine.

Example

# vars.py
from typing import Dict

VALUES: Dict[str, int] = {}
VALUES["foo"] = 1
VALUES["bar"] = 2

FOO: str = "foo"
BAR: int = 1
*** Settings ***
Variables    vars.py

*** Test Cases ***
Demo
    Log    ${VALUES}
    Log    ${FOO}
    Log    ${BAR}

Screenshots
image

Versions:

  • OS: Win 10
  • Robot Framework Language Server Version: 0.42.0
  • Client Version: 1.65.2
@JaPyR JaPyR added bug Something isn't working robotframework-ls labels Mar 30, 2022
@vtpeters
Copy link

vtpeters commented Mar 30, 2022

I have the same experience, but also with variables that are built-in...

In a piece of code in one of my test cases I've constructed a List object containing files/documents.

With the FOR...IN statement I iterate through the List object and upload each file to a web page...
FOR ${document} IN @{documenten} ... END

After (automatically) upgrading to Robot Framework Language Server 0.43.x I noticed that the variable ${document} in the code had a wiggly line under it, indicating that there might be a syntax error. But the code runs fine, without error.

Screenshot after upgrading...
image

Downgrading to Robot Framework Language Server 0.42.0 solved the issue. The wiggly lines were gone and the code still runs fine without errors.

OS: Win10
Microsoft VS Code: 1.65.2
Robot Framework 3.2.2
Robot Framework Language Server: 0.42.0

@pedrothaines
Copy link

I'm facing a very similar issue.

This might be related to #628.

@fabioz fabioz closed this as completed in e93af19 Mar 30, 2022
@fabioz
Copy link
Collaborator

fabioz commented Mar 30, 2022

There really was an issue in the static analysis when dealing with annotated assigns.

Thanks for the report. I've just fixed that.

p.s.: for others facing issues with undefined variables, if it's not exactly the case of annotated assigns, please create different issues.
(or maybe take a look at: https://github.com/robocorp/robotframework-lsp/blob/master/robotframework-ls/docs/faq.md#how-to-deal-with-undefined-variables for how to deal with undefined variables in general).

@fabioz
Copy link
Collaborator

fabioz commented Mar 30, 2022

@vtpeters as a note, if your info is correct, you're using a FOR statement in Robot Framework 3... I believe FOR statements are only valid in RF4... if that's not your issue, please create a different issue.

@fabioz
Copy link
Collaborator

fabioz commented Mar 30, 2022

As a note, I've just published a pre-release (0.43.4) with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working robotframework-ls
Projects
None yet
Development

No branches or pull requests

4 participants