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

Syntax error for passing kwargs to a function inside fstrings #45

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

@TotallyNotChase
Copy link

Environment data

  • Language Server version: 2020.6.1
  • OS and version: Microsoft Windows [Version 10.0.19041.329]
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.4

Expected behaviour

Passing a dictionary to a function inside an fstring should not show any syntax errors.

Actual behaviour

Pylance shows syntax error when encountering a dict ({}) inside an fstring

Logs

Doubt the logs would be useful, but here they are anyway-

[Info  - 5:07:38 PM] Pylance language server 2020.6.1 starting
[Info  - 5:07:38 PM] Server root directory: c:\Users\Chase\.vscode\extensions\ms-python.vscode-pylance-2020.6.1\server
[Info  - 5:07:38 PM] No configuration file found.
[Info  - 5:07:38 PM] Setting pythonPath for service "test": "C:\Users\Chase\AppData\Local\Programs\Python\Python37-32\python.exe"
[Info  - 5:07:39 PM] stubPath c:\Users\Chase\Desktop\Python Projects\test\typings is not a valid directory.
[Info  - 5:07:39 PM] Assuming Python version 3.7
[Info  - 5:07:39 PM] Assuming Python platform Windows
[Info  - 5:07:39 PM] Searching for source files
[Info  - 5:07:39 PM] Found 1 source file
[Info  - 5:07:39 PM] Background analysis root directory: c:\Users\Chase\.vscode\extensions\ms-python.vscode-pylance-2020.6.1\server
[Info  - 5:07:39 PM] Background analysis started
[FG] parsing: c:\Users\Chase\Desktop\Python Projects\test\test.py (31ms)
[FG] parsing: c:\Users\Chase\.vscode\extensions\ms-python.vscode-pylance-2020.6.1\server\typeshed-fallback\stdlib\2and3\builtins.pyi (377ms)
[FG] binding: c:\Users\Chase\.vscode\extensions\ms-python.vscode-pylance-2020.6.1\server\typeshed-fallback\stdlib\2and3\builtins.pyi (156ms)
[FG] binding: c:\Users\Chase\Desktop\Python Projects\test\test.py (2ms)
[BG] analyzing: c:\Users\Chase\Desktop\Python Projects\test\test.py ...
[BG]   parsing: c:\Users\Chase\Desktop\Python Projects\test\test.py (169ms)
[BG]   parsing: c:\Users\Chase\.vscode\extensions\ms-python.vscode-pylance-2020.6.1\server\typeshed-fallback\stdlib\2and3\builtins.pyi (380ms)
[BG]   binding: c:\Users\Chase\.vscode\extensions\ms-python.vscode-pylance-2020.6.1\server\typeshed-fallback\stdlib\2and3\builtins.pyi (146ms)
[BG]   binding: c:\Users\Chase\Desktop\Python Projects\test\test.py (1ms)
[BG]   checking: c:\Users\Chase\Desktop\Python Projects\test\test.py ...
[BG]     parsing: c:\Users\Chase\.vscode\extensions\ms-python.vscode-pylance-2020.6.1\server\typeshed-fallback\stdlib\3\typing.pyi (78ms)
[BG]     binding: c:\Users\Chase\.vscode\extensions\ms-python.vscode-pylance-2020.6.1\server\typeshed-fallback\stdlib\3\typing.pyi (39ms)
[BG]     parsing: c:\Users\Chase\.vscode\extensions\ms-python.vscode-pylance-2020.6.1\server\typeshed-fallback\stdlib\2and3\_typeshed\__init__.pyi (18ms)
[BG]     binding: c:\Users\Chase\.vscode\extensions\ms-python.vscode-pylance-2020.6.1\server\typeshed-fallback\stdlib\2and3\_typeshed\__init__.pyi (3ms)
[BG]   checking: c:\Users\Chase\Desktop\Python Projects\test\test.py (187ms)
[BG] analyzing: c:\Users\Chase\Desktop\Python Projects\test\test.py (890ms)
[FG] parsing: c:\Users\Chase\.vscode\extensions\ms-python.vscode-pylance-2020.6.1\server\typeshed-fallback\stdlib\3\typing.pyi (68ms)
[FG] binding: c:\Users\Chase\.vscode\extensions\ms-python.vscode-pylance-2020.6.1\server\typeshed-fallback\stdlib\3\typing.pyi (36ms)
[FG] parsing: c:\Users\Chase\.vscode\extensions\ms-python.vscode-pylance-2020.6.1\server\typeshed-fallback\stdlib\2and3\_typeshed\__init__.pyi (23ms)
[FG] binding: c:\Users\Chase\.vscode\extensions\ms-python.vscode-pylance-2020.6.1\server\typeshed-fallback\stdlib\2and3\_typeshed\__init__.pyi (8ms)

Code Snippet / Additional information

from typing import Dict

def foo(spam, dictval: Dict):
    print(dictval)
    return "Done"

print(f"{foo(0, {'bar' : 1, 'baz': 2})}")

Output after python ./test.py in the commandline-

{'bar': 1, 'baz': 2}
Done

The code doesn't actually cause a syntax error as you can see. But Pylance reports syntax error-

image

It also shows a parameter missing error, however that's certainly a side effect of the syntax error-

image

@erictraut
Copy link
Contributor

Thanks for the bug report. Pylance was not correctly handling nested braces within an f-string expression. It is now working. The fix will be in an upcoming 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 labels Jul 4, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2020.7.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202070-9-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

3 participants