Viswanath
Viswanath

Reputation: 1033

Syntax errors with parsing f-strings in PyDev Eclipse

I've a python project using PyDev in Eclipse. For sample code like below,

var = 'element'
width = 11
print(f'{var:>{width}}')

the code is executed printing the desired output element with right alignment and no errors.

However, PyDev parses this code raising error at > character and an error message SyntaxError: Unbalanced '{'. But PyDev does support double braces in f-strings since release 6.3.1 (#PyDev-884). If I remove this > character, the string is printed 'left-aligned' (which I don't want) and PyDev doesn't raise any error. This confirms PyDev does support double braces, but the error message is incorrect.

On the other hand, PEP 498 for f-strings doesn't mention anything about alignment using f-strings. Is alignment part of the f-string syntax? If it is why is it not mentioned in PEP guide, and why does PyDev parser raise an error?

  1. Python: 3.6.3
  2. PyDev: 6.3.3
  3. Eclipse: Oxygen.2 (4.7.2)

Thanks!

Upvotes: 1

Views: 1200

Answers (1)

Fabio Zadrozny
Fabio Zadrozny

Reputation: 25342

This is an issue in PyDev (unfortunately https://www.python.org/dev/peps/pep-0498/ does not provide a grammar for f-strings and is very light on how the expected parsing should take place -- I'll update PyDev to cover for the provided example).

Upvotes: 2

Related Questions