Search code examples
python-3.xsublimetext3python-3.6sublime-text-plugin

Pyflakes "invalid syntax" and print function's variable in curly braces


I has Sublime Text 3 installed, SublimeLinter plugin and pyflakes linter. In the pip pyflakes version is 1.6.0. OS win 7 x86.

my_name = 'Name'
print(f"My name is {my_name}.")

And here is the error:

SublimeLinter: pyflakes output:
ex3.py:9:30: invalid syntax
print(f"My name is {my_name}.")
                             ^ 

Also, with this construction i have no errors:

print("My name is {}.".format(my_name))

Code is runing just fine, but why pyflakes gives me this error then? Is it pyflakes issue or what?


Solution

  • This is a known issue, see here:

    https://gitlab.com/pycqa/flake8/issues/296

    It seems to be fixed in current version...

    Edit: Since you are on the latest version, maybe you are running into an issue of sublime-linter, like here:

    https://forum.sublimetext.com/t/sublimelinter-pyflakes-not-matching-pyflakes-from-cli/31348/3

    To test this, you could run the pyflakes command in the command line outside of sublime to see whether it works.

    Edit2: As per the asker's comment, using SublimeLinter-flake8 instead of SublimeLinter-pyflakes is compatible with f-strings from python 3.6+.

    (Also, sorry for the double posted answer. And thanks for deleting one, @Andy. I don't know what happened there.)