f-strings everywhere

This commit is contained in:
David Lord 2020-04-04 11:39:03 -07:00
parent 524fd0bc8c
commit 2ae740dd49
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
35 changed files with 227 additions and 245 deletions

View file

@ -103,7 +103,7 @@ error messages could be displayed with a red background.
To flash a message with a different category, just use the second argument
to the :func:`~flask.flash` function::
flash(u'Invalid password provided', 'error')
flash('Invalid password provided', 'error')
Inside the template you then have to tell the
:func:`~flask.get_flashed_messages` function to also return the

View file

@ -93,7 +93,7 @@ write this by having a function that calls into
name and a dot, and by wrapping `view_func` in a `LazyView` as needed. ::
def url(import_name, url_rules=[], **options):
view = LazyView('yourapplication.' + import_name)
view = LazyView(f"yourapplication.{import_name}")
for url_rule in url_rules:
app.add_url_rule(url_rule, view_func=view, **options)

View file

@ -52,4 +52,4 @@ Example usage::
files = request.files
# At this point the hash is fully constructed.
checksum = hash.hexdigest()
return 'Hash was: %s' % checksum
return f"Hash was: {checksum}"

View file

@ -104,9 +104,9 @@ You can insert entries into the database like this:
Querying is simple as well:
>>> User.query.all()
[<User u'admin'>]
[<User 'admin'>]
>>> User.query.filter(User.name == 'admin').first()
<User u'admin'>
<User 'admin'>
.. _SQLAlchemy: https://www.sqlalchemy.org/
.. _declarative:
@ -200,19 +200,19 @@ SQLAlchemy will automatically commit for us.
To query your database, you use the engine directly or use a connection:
>>> users.select(users.c.id == 1).execute().first()
(1, u'admin', u'admin@localhost')
(1, 'admin', 'admin@localhost')
These results are also dict-like tuples:
>>> r = users.select(users.c.id == 1).execute().first()
>>> r['name']
u'admin'
'admin'
You can also pass strings of SQL statements to the
:meth:`~sqlalchemy.engine.base.Connection.execute` method:
>>> engine.execute('select * from users where id = :1', [1]).first()
(1, u'admin', u'admin@localhost')
(1, 'admin', 'admin@localhost')
For more information about SQLAlchemy, head over to the
`website <https://www.sqlalchemy.org/>`_.

View file

@ -21,7 +21,7 @@ data and to then invoke that function and pass it to a response object::
def generate_large_csv():
def generate():
for row in iter_all_rows():
yield ','.join(row) + '\n'
yield f"{','.join(row)}\n"
return Response(generate(), mimetype='text/csv')
Each ``yield`` expression is directly sent to the browser. Note though

View file

@ -142,8 +142,7 @@ Here is the code for that decorator::
def decorated_function(*args, **kwargs):
template_name = template
if template_name is None:
template_name = request.endpoint \
.replace('.', '/') + '.html'
template_name = f"'{request.endpoint.replace('.', '/')}.html'"
ctx = f(*args, **kwargs)
if ctx is None:
ctx = {}