Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github Action flake8 fails: f-string is missing placeholders

Following the course "FastAPI-TDD with Docker" I got the project to build and pass locally, then in the github action it fails:

It seems the offensive line in the source is:

    response = test_app_with_db.get(f"/summaries/")

and the Github Action result is:

Run docker exec fastapi-tdd python -m flake8 .
  docker exec fastapi-tdd python -m flake8 .
  shell: /bin/bash -e {0}
  env:
    IMAGE: docker.pkg.github.com/$GITHUB_REPOSITORY/web
./app/db.py:14:1: E303 too many blank lines (3)
./tests/test_ping.py:4:1: F401 'app.main' imported but unused
./tests/test_summaries.py:6:1: F401 'pytest' imported but unused
./tests/test_summaries.py:60:37: F541 f-string is missing placeholders
##[error]Process completed with exit code 1.
like image 809
Blaise Pabon Avatar asked Jun 25 '20 00:06

Blaise Pabon


2 Answers

f string work with place holder Example : If you want to put '/summary/' in f string assign it to some variable then put that variable in place holder

Syntax is

f'{variable}'

Example :

f'{"quoted string"}'
like image 76
Abhisek Singh Avatar answered Oct 24 '22 23:10

Abhisek Singh


I got the error on my when checking my code with flake8. The problem its simply that I was using a f-string for something that could be just a string.

f-string make sense when you insert variables for example:

Correct use of f-string

age = 34
print(f'Hi my name is Enrique and my age is {age} years old')

but if you are just puting a string withou variables then you are making a wrong use of f-string

Incorrect use of f-string

print(f'Hi my name is Enrique and my age is 34 years old')

In that case you don´t need to use the f-string as you are not inserting any variable in your string

like image 45
Enrique Benito Casado Avatar answered Oct 24 '22 22:10

Enrique Benito Casado