question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

syntax error with f-strings

See original GitHub issue

Environment data

  • VSCode Info: Version: 1.34.0-insider Commit: 0ab39f4148f242e7b0802330385fc99b4845aa31 Date: 2019-04-08T05:13:56.940Z Electron: 3.1.8 Chrome: 66.0.3359.181 Node.js: 10.2.0 V8: 6.6.346.32 OS: Linux x64 5.0.5-200.fc29.x86_64 (Fedora 29)
  • VS Code version: 1.34.0-insider (commit 0ab39f414)
  • Extension version (available under the Extensions sidebar): 2019.3.6558 (8 April 2019)
  • OS and version: Linux x64 5.0.5-200.fc29.x86_64 (Fedora 29)
  • Python version (& distribution if applicable, e.g. Anaconda): pypy3.5-6.0.0
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): pyenv
  • Relevant/affected Python packages and their versions: XXX

Expected behaviour

When using the new format string specifier, the code should be valid, and not display any problem.

Actual behaviour

When using the new format string specifier, the code is not valid, and displays the problems:

invalid syntax Python(parser-16) [24, 54]
Undefined variable: 'f' Python(undefined-variable) [24, 53]

In this screenshot, you can see the issues: screenshot-parser-16-error

Steps to reproduce:

  1. create a new python file
  2. paste the following into the file:
print(f"I like the number {3}.")
  1. save and wait a few minutes (it takes a bit for the errors to be displayed.)

Logs

{
	"resource": "[...]/elastic_mixin.py",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": "parser-16",
	"severity": 8,
	"message": "invalid syntax",
	"source": "Python",
	"startLineNumber": 24,
	"startColumn": 54,
	"endLineNumber": 24,
	"endColumn": 71
}
{
	"resource": "[...]/elastic_mixin.py",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": "undefined-variable",
	"severity": 4,
	"message": "Undefined variable: 'f'",
	"source": "Python",
	"startLineNumber": 24,
	"startColumn": 53,
	"endLineNumber": 24,
	"endColumn": 54
}

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

( no output )

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Linightzcommented, Jun 18, 2019

I’m using python 3.7.3 and this exact same issue happens to me too.

0reactions
jakebaileycommented, Sep 12, 2019

For reference, there are two issues here:

  • An actual syntax error when the code runs (the code runner thing, not our bug)
  • PyPy’s backported fstring syntax support (which is that LS issue)
Read more comments on GitHub >

github_iconTop Results From Across the Web

python - f-strings giving SyntaxError? - Stack Overflow
I have python 3.6 installed and still get this error. Some program must still be running python 3.5 which I also have installed....
Read more >
SyntaxError: f-string: expecting '}' in Python | bobbyhadz
The Python "SyntaxError: f-string: expecting '}'" occurs when we use single quotes inside of an f-string that was wrapped using single quotes.
Read more >
Python 3 SyntaxError: invalid syntax f strings - Softhints
I was working on a old python project and I got error: filename = f"{file}_{user.replace('/', '_')}.txt" ^ SyntaxError: invalid syntax.
Read more >
Question regarding Python 3.9 unable to read f strings
If I try to print them I'm given a syntax error. For the f string exercise one I just started running the full...
Read more >
Invalid syntax with an f-string - Python Forum
I'll try to start using f-strings and getting used to this. Thanks!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found