Skip to content

Commit

Permalink
Use f-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Aug 30, 2021
1 parent b4890e3 commit 9bc1306
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pgsu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,15 @@ def _execute_su_psql(command, dsn, interactive=False, stderr=None):

database = dsn.get('database')
if database:
psql_option_str += '-d {}'.format(database)
psql_option_str += f'-d {database}'

# to do: Forward password to psql; ignore host only when the password is None. # pylint: disable=fixme
# Note: There is currently no known postgresql setup that needs this, though
# password = dsn.get('password')

host = dsn.pop('host', 'localhost')
if host and host != 'localhost':
psql_option_str += ' -h {}'.format(host)
psql_option_str += f' -h {host}'
else:
LOGGER.debug(
"Found host 'localhost' but dropping '-h localhost' option for psql "
Expand All @@ -333,7 +333,7 @@ def _execute_su_psql(command, dsn, interactive=False, stderr=None):

port = dsn.get('port')
if port:
psql_option_str += ' -p {}'.format(port)
psql_option_str += f' -p {port}'

# Note: This is *both* the UNIX user to become *and* the database user
user = dsn.get('user')
Expand Down Expand Up @@ -384,7 +384,7 @@ def escape_for_bash(str_to_escape):
string found below.
"""
escaped_quotes = str_to_escape.replace("'", """'"'"'""")
return "'{}'".format(escaped_quotes)
return f"'{escaped_quotes}'"


def unique_list(non_unique_list):
Expand Down
2 changes: 1 addition & 1 deletion pgsu/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
def run(query):
"""Execute SQL command as PostrgreSQL superuser."""
pgsu = PGSU(interactive=True, quiet=False)
click.echo('Executing query: {}'.format(query))
click.echo(f'Executing query: {query}')
dbs = pgsu.execute(query)
click.echo(pprint.pformat(dbs))

0 comments on commit 9bc1306

Please sign in to comment.