Merge pull request #3406 from erfanio/f-string-docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Change docs to use f-strings
authored by David Lord · committed by GitHub · parents b5d9084, 07caa44 · Browse files · 7 files·+13 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+13 added−13 removed
- other:+13 added−13 removed
Provenance
- Commit
2659f0a- Tree
77a9902- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
b5d9084- Parent 2
07caa44
7 files changed+13 added−13 removed
modified:docs/patterns/fabric.rst+4 added-4 removed
47 unmodified lines48 49 def deploy():50 # figure out the package name and version51 dist = local('python setup.py --fullname', capture=True).strip()52- filename = '%s.tar.gz' % dist52+ filename = f'{dist}.tar.gz'53 54 # upload the package to the temporary folder on the server55- put('dist/%s' % filename, '/tmp/%s' % filename)55+ put(f'dist/{filename}', f'/tmp/{filename}')56 57 # install the package in the application's virtualenv with pip58- run('/var/www/yourapplication/env/bin/pip install /tmp/%s' % filename)58+ run(f'/var/www/yourapplication/env/bin/pip install /tmp/{filename}')59 60 # remove the uploaded package61- run('rm -r /tmp/%s' % filename)61+ run(f'rm -r /tmp/{filename}')62 63 # touch the .wsgi file to trigger a reload in mod_wsgi64 run('touch /var/www/yourapplication.wsgi')65 121 unmodified linesmodified:docs/patterns/sqlalchemy.rst+2 added-2 removed
84 unmodified lines85 self.name = name86 self.email = email87 88 def __repr__(self):89- return '<User %r>' % (self.name)89+ return f'<User {self.name!r}>'90 91 To create the database you can use the `init_db` function:92 93 >>> from yourapplication.database import init_db64 unmodified lines158 self.name = name159 self.email = email160 161 def __repr__(self):162- return '<User %r>' % (self.name)162+ return f'<User {self.name!r}>'163 164 users = Table('users', metadata,165 Column('id', Integer, primary_key=True),166 Column('name', String(50), unique=True),52 unmodified linesmodified:docs/patterns/viewdecorators.rst+2 added-2 removed
80 unmodified lines81 82 from functools import wraps83 from flask import request84 85- def cached(timeout=5 * 60, key='view/%s'):85+ def cached(timeout=5 * 60, key='view/{}'):86 def decorator(f):87 @wraps(f)88 def decorated_function(*args, **kwargs):89- cache_key = key % request.path89+ cache_key = key.format(request.path)90 rv = cache.get(cache_key)91 if rv is not None:92 return rv93 rv = f(*args, **kwargs)79 unmodified linesmodified:docs/blueprints.rst+1 added-1 removed
68 unmodified lines69 @simple_page.route('/', defaults={'page': 'index'})70 @simple_page.route('/<page>')71 def show(page):72 try:73- return render_template('pages/%s.html' % page)73+ return render_template(f'pages/{page}.html')74 except TemplateNotFound:75 abort(404)76 77 When you bind a function with the help of the ``@simple_page.route``200 unmodified linesmodified:docs/signals.rst+1 added-1 removed
177 unmodified lines178 from flask import template_rendered179 180 @template_rendered.connect_via(app)181 def when_template_rendered(sender, template, context, **extra):182- print 'Template %s is rendered with %s' % (template.name, context)182+ print f'Template {template.name} is rendered with {context}'183 184 Core Signals185 ------------186 4 unmodified linesmodified:docs/styleguide.rst+2 added-2 removed
49 unmodified lines50 else by one. Do not use too many blank lines to separate logical51 segments in code. Example::52 53 def hello(name):54- print 'Hello %s!' % name54+ print f'Hello {name}!'55 56 57 def goodbye(name):58- print 'See you %s.' % name58+ print f'See you {name}.'59 60 61 class MyClass(object):62 """This is a simple docstring"""138 unmodified linesmodified:docs/views.rst+1 added-1 removed
229 unmodified lines230 view_func = view.as_view(endpoint)231 app.add_url_rule(url, defaults={pk: None},232 view_func=view_func, methods=['GET',])233 app.add_url_rule(url, view_func=view_func, methods=['POST',])234- app.add_url_rule('%s<%s:%s>' % (url, pk_type, pk), view_func=view_func,234+ app.add_url_rule(f'{url}<{pk_type}:{pk}>', view_func=view_func,235 methods=['GET', 'PUT', 'DELETE'])236 237 register_api(UserAPI, 'user_api', '/users/', pk='user_id')