Target session attr (Sourcery refactored)#3
Target session attr (Sourcery refactored)#3sourcery-ai[bot] wants to merge 1 commit intotarget_session_attrfrom
Conversation
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.09%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
22a09c9 to
e665b3c
Compare
| drop_script = [] | ||
| drop_script.append('DROP ROLE ssl_user;') | ||
| drop_script = ['DROP ROLE ssl_user;'] |
There was a problem hiding this comment.
Function BaseTestSSLConnection.tearDown refactored with the following changes:
- Merge append into list declaration (
merge-list-append)
| dsn='postgresql://foo/postgres?sslmode=' + sslmode, | ||
| dsn=f'postgresql://foo/postgres?sslmode={sslmode}', | ||
| host=host, | ||
| user='ssl_user') | ||
| user='ssl_user', | ||
| ) |
There was a problem hiding this comment.
Function TestSSLConnection.test_ssl_connection_sslmode refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| dsn = 'postgres://ssl_user@localhost/postgres?' + params_str | ||
| dsn = f'postgres://ssl_user@localhost/postgres?{params_str}' | ||
| await self._test_works(dsn=dsn) | ||
|
|
||
| params['sslkey'] = CLIENT_SSL_PROTECTED_KEY_FILE | ||
| params['sslpassword'] = 'secRet' | ||
| params_str = urllib.parse.urlencode(params) | ||
| dsn = 'postgres://ssl_user@localhost/postgres?' + params_str | ||
| dsn = f'postgres://ssl_user@localhost/postgres?{params_str}' |
There was a problem hiding this comment.
Function TestClientSSLConnection.test_ssl_connection_client_auth_dsn refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| await self._test_works(dsn=dsn + '&sslpassword=secRet') | ||
| await self._test_works(dsn=f'{dsn}&sslpassword=secRet') |
There was a problem hiding this comment.
Function TestClientSSLConnection.test_ssl_connection_client_auth_env refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| await self._test_works(dsn=dsn + '&sslpassword=secRet') | ||
| await self._test_works(dsn=f'{dsn}&sslpassword=secRet') |
There was a problem hiding this comment.
Function TestClientSSLConnection.test_ssl_connection_client_auth_dot_postgresql refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| dsn='postgresql://foo/postgres?sslmode=' + sslmode, | ||
| dsn=f'postgresql://foo/postgres?sslmode={sslmode}', | ||
| host=host, | ||
| user='ssl_user') | ||
| user='ssl_user', | ||
| ) |
There was a problem hiding this comment.
Function TestNoSSLConnection.test_nossl_connection_sslmode refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
e665b3c to
e3926f7
Compare
| PGPASSFILE = 'pgpass.conf' | ||
| else: | ||
| PGPASSFILE = '.pgpass' | ||
| PGPASSFILE = 'pgpass.conf' if _system == 'Windows' else '.pgpass' |
There was a problem hiding this comment.
Lines 77-80 refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| def _read_password_file(passfile: pathlib.Path) \ | ||
| -> typing.List[typing.Tuple[str, ...]]: | ||
| def _read_password_file(passfile: pathlib.Path) -> typing.List[typing.Tuple[str, ...]]: |
There was a problem hiding this comment.
Function _read_password_file refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| if phost != '*' and phost != host: | ||
| if phost not in ['*', host]: | ||
| continue | ||
| if pport != '*' and pport != str(port): | ||
| if pport not in ['*', str(port)]: | ||
| continue | ||
| if pdatabase != '*' and pdatabase != database: | ||
| if pdatabase not in ['*', database]: | ||
| continue | ||
| if puser != '*' and puser != user: | ||
| if puser not in ['*', user]: |
There was a problem hiding this comment.
Function _read_password_from_pgpass refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator [×4] (merge-comparisons)
| 'could not match {} port numbers to {} hosts'.format( | ||
| len(port), len(hosts))) | ||
| f'could not match {len(port)} port numbers to {len(hosts)} hosts' | ||
| ) |
There was a problem hiding this comment.
Function _validate_port_spec refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| if ',' in hostlist: | ||
| # A comma-separated list of host addresses. | ||
| hostspecs = hostlist.split(',') | ||
| else: | ||
| hostspecs = [hostlist] | ||
|
|
||
| hostspecs = hostlist.split(',') if ',' in hostlist else [hostlist] | ||
| hosts = [] | ||
| hostlist_ports = [] | ||
|
|
||
| if not port: | ||
| portspec = os.environ.get('PGPORT') | ||
| if portspec: | ||
| if portspec := os.environ.get('PGPORT'): |
There was a problem hiding this comment.
Function _parse_hostlist refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Use named expression to simplify assignment and conditional [×2] (
use-named-expression) - Replace m.group(x) with m[x] for re.Match objects [×2] (
use-getitem-for-re-match-groups) - Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
This removes the following comments ( why? ):
# IPv6 address
# A comma-separated list of host addresses.
| tabname = utils._quote_ident(schema_name) + '.' + tabname | ||
| tabname = f'{utils._quote_ident(schema_name)}.{tabname}' | ||
|
|
||
| if columns: | ||
| col_list = ', '.join(utils._quote_ident(c) for c in columns) | ||
| cols = '({})'.format(col_list) | ||
| cols = f'({col_list})' |
There was a problem hiding this comment.
Function Connection.copy_records_to_table refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation) - Replace call to format with f-string (
use-fstring-for-formatting)
| opts.append('{} {}'.format(k.upper(), v)) | ||
| opts.append(f'{k.upper()} {v}') | ||
|
|
||
| if opts: | ||
| return '(' + ', '.join(opts) + ')' | ||
| else: | ||
| return '' | ||
| return '(' + ', '.join(opts) + ')' if opts else '' |
There was a problem hiding this comment.
Function Connection._format_copy_opts refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting) - Replace if statement with if expression (
assign-if-exp)
| 'cannot use custom codec on non-scalar type {}.{}'.format( | ||
| schema, typename)) | ||
| f'cannot use custom codec on non-scalar type {schema}.{typename}' | ||
| ) |
There was a problem hiding this comment.
Function Connection.set_type_codec refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| 'cannot alias non-scalar type {}.{}'.format( | ||
| schema, typename)) | ||
| f'cannot alias non-scalar type {schema}.{typename}' | ||
| ) |
There was a problem hiding this comment.
Function Connection.set_builtin_type_codec refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| if self._proxy is None: | ||
| con_ref = self | ||
| else: | ||
| # `_proxy` is not None when the connection is a member | ||
| # of a connection pool. Which means that the user is working | ||
| # with a `PoolConnectionProxy` instance, and expects to see it | ||
| # (and not the actual Connection) in their event callbacks. | ||
| con_ref = self._proxy | ||
| return con_ref | ||
| return self if self._proxy is None else self._proxy |
There was a problem hiding this comment.
Function Connection._unwrap refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# with a `PoolConnectionProxy` instance, and expects to see it
# `_proxy` is not None when the connection is a member
# (and not the actual Connection) in their event callbacks.
# of a connection pool. Which means that the user is working
| elif hasattr(connection_settings, 'crdb_version'): | ||
| elif hasattr(connection_settings, 'crdb_version') or hasattr( | ||
| connection_settings, 'crate_version' | ||
| ): | ||
| # CockroachDB detected. | ||
| advisory_locks = False | ||
| notifications = False | ||
| plpgsql = False | ||
| sql_reset = False | ||
| sql_close_all = False | ||
| elif hasattr(connection_settings, 'crate_version'): | ||
| # CrateDB detected. |
There was a problem hiding this comment.
Function _detect_server_capabilities refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks) - Remove redundant conditional (
remove-redundant-if)
This removes the following comments ( why? ):
# CrateDB detected.
| formatted = [] | ||
|
|
||
| for i, context in enumerate(self.__unhandled_exceptions): | ||
| formatted.append(self._format_loop_exception(context, i + 1)) | ||
| formatted = [ | ||
| self._format_loop_exception(context, i + 1) | ||
| for i, context in enumerate(self.__unhandled_exceptions) | ||
| ] |
There was a problem hiding this comment.
Function TestCase.tearDown refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| value = 'Object created at (most recent call last):\n' | ||
| value += tb.rstrip() | ||
| value = 'Object created at (most recent call last):\n' + tb.rstrip() | ||
| else: | ||
| try: | ||
| value = repr(value) | ||
| except Exception as ex: | ||
| value = ('Exception in __repr__ {!r}; ' | ||
| 'value type: {!r}'.format(ex, type(value))) | ||
| lines.append('[{}]: {}\n\n'.format(key, value)) | ||
| lines.append(f'[{key}]: {value}\n\n') |
There was a problem hiding this comment.
Function TestCase._format_loop_exception refactored with the following changes:
- Replace assignment and augmented assignment with single assignment (
merge-assign-and-aug-assign) - Replace call to format with f-string (
use-fstring-for-formatting)
| if not initdb_options: | ||
| initdb_options = {} | ||
| else: | ||
| initdb_options = dict(initdb_options) | ||
|
|
||
| initdb_options = dict(initdb_options) if initdb_options else {} |
There was a problem hiding this comment.
Function _get_initdb_options refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Swap if/else branches of if expression to remove negation (
swap-if-expression)
| pg_host = os.environ.get('PGHOST') | ||
| if pg_host: | ||
| if pg_host := os.environ.get('PGHOST'): |
There was a problem hiding this comment.
Function _init_default_cluster refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| drop_script.append('DROP ROLE {}_user;'.format(username)) | ||
| drop_script.append(f'DROP ROLE {username}_user;') |
There was a problem hiding this comment.
Function TestAuthentication.tearDown refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| for tried in range(3): | ||
| try: | ||
| for _ in range(3): | ||
| with contextlib.suppress(asyncpg.ConnectionDoesNotExistError): | ||
| return await self.connect(**kwargs) | ||
| except asyncpg.ConnectionDoesNotExistError: | ||
| pass | ||
|
|
There was a problem hiding this comment.
Function TestAuthentication._try_connect refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Use
contextlib'ssuppressmethod to silence an error (use-contextlib-suppress)
| old_vals = {} | ||
| for key in kwargs: | ||
| if key in os.environ: | ||
| old_vals[key] = os.environ[key] | ||
|
|
||
| old_vals = {key: os.environ[key] for key in kwargs if key in os.environ} |
There was a problem hiding this comment.
Function TestConnectParams.environ refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension)
| test_env.update(env) | ||
| test_env |= env |
There was a problem hiding this comment.
Function TestConnectParams.run_testcase refactored with the following changes:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union) - Replace call to format with f-string (
use-fstring-for-formatting)
| self.run_testcase({ | ||
| 'dsn': 'postgres://user@abc/db?passfile={}'.format( | ||
| passfile.name), | ||
| 'result': ( | ||
| [('abc', 5432)], | ||
| { | ||
| 'password': 'password from pgpass for user@abc', | ||
| 'user': 'user', | ||
| 'database': 'db', | ||
| } | ||
| ) | ||
| }) | ||
| self.run_testcase( | ||
| { | ||
| 'dsn': f'postgres://user@abc/db?passfile={passfile.name}', | ||
| 'result': ( | ||
| [('abc', 5432)], | ||
| { | ||
| 'password': 'password from pgpass for user@abc', | ||
| 'user': 'user', | ||
| 'database': 'db', | ||
| }, | ||
| ), | ||
| } | ||
| ) |
There was a problem hiding this comment.
Function TestConnectParams.test_connect_pgpass_regular refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| dsn='postgresql://foo/?sslmode=' + sslmode, | ||
| dsn=f'postgresql://foo/?sslmode={sslmode}', | ||
| user='postgres', | ||
| database='postgres', | ||
| host='localhost') | ||
| host='localhost', | ||
| ) |
There was a problem hiding this comment.
Function TestConnection.test_connection_sslmode_no_ssl_server refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| create_script = [] | ||
| create_script.append('CREATE ROLE ssl_user WITH LOGIN;') | ||
|
|
||
| create_script = ['CREATE ROLE ssl_user WITH LOGIN;'] |
There was a problem hiding this comment.
Function BaseTestSSLConnection.setUp refactored with the following changes:
- Merge append into list declaration (
merge-list-append)
| drop_script = [] | ||
| drop_script.append('DROP ROLE ssl_user;') | ||
| drop_script = ['DROP ROLE ssl_user;'] |
There was a problem hiding this comment.
Function BaseTestSSLConnection.tearDown refactored with the following changes:
- Merge append into list declaration (
merge-list-append)
| dsn='postgresql://foo/postgres?sslmode=' + sslmode, | ||
| dsn=f'postgresql://foo/postgres?sslmode={sslmode}', | ||
| host=host, | ||
| user='ssl_user') | ||
| user='ssl_user', | ||
| ) |
There was a problem hiding this comment.
Function TestSSLConnection.test_ssl_connection_sslmode refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| dsn = 'postgres://ssl_user@localhost/postgres?' + params_str | ||
| dsn = f'postgres://ssl_user@localhost/postgres?{params_str}' | ||
| await self._test_works(dsn=dsn) | ||
|
|
||
| params['sslkey'] = CLIENT_SSL_PROTECTED_KEY_FILE | ||
| params['sslpassword'] = 'secRet' | ||
| params_str = urllib.parse.urlencode(params) | ||
| dsn = 'postgres://ssl_user@localhost/postgres?' + params_str | ||
| dsn = f'postgres://ssl_user@localhost/postgres?{params_str}' |
There was a problem hiding this comment.
Function TestClientSSLConnection.test_ssl_connection_client_auth_dsn refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| await self._test_works(dsn=dsn + '&sslpassword=secRet') | ||
| await self._test_works(dsn=f'{dsn}&sslpassword=secRet') |
There was a problem hiding this comment.
Function TestClientSSLConnection.test_ssl_connection_client_auth_env refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| await self._test_works(dsn=dsn + '&sslpassword=secRet') | ||
| await self._test_works(dsn=f'{dsn}&sslpassword=secRet') |
There was a problem hiding this comment.
Function TestClientSSLConnection.test_ssl_connection_client_auth_dot_postgresql refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| dsn='postgresql://foo/postgres?sslmode=' + sslmode, | ||
| dsn=f'postgresql://foo/postgres?sslmode={sslmode}', | ||
| host=host, | ||
| user='ssl_user') | ||
| user='ssl_user', | ||
| ) |
There was a problem hiding this comment.
Function TestNoSSLConnection.test_nossl_connection_sslmode refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
e3926f7 to
a7674f2
Compare
| PGPASSFILE = 'pgpass.conf' | ||
| else: | ||
| PGPASSFILE = '.pgpass' | ||
| PGPASSFILE = 'pgpass.conf' if _system == 'Windows' else '.pgpass' |
There was a problem hiding this comment.
Lines 77-80 refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| def _read_password_file(passfile: pathlib.Path) \ | ||
| -> typing.List[typing.Tuple[str, ...]]: | ||
| def _read_password_file(passfile: pathlib.Path) -> typing.List[typing.Tuple[str, ...]]: |
There was a problem hiding this comment.
Function _read_password_file refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| if phost != '*' and phost != host: | ||
| if phost not in ['*', host]: | ||
| continue | ||
| if pport != '*' and pport != str(port): | ||
| if pport not in ['*', str(port)]: | ||
| continue | ||
| if pdatabase != '*' and pdatabase != database: | ||
| if pdatabase not in ['*', database]: | ||
| continue | ||
| if puser != '*' and puser != user: | ||
| if puser not in ['*', user]: |
There was a problem hiding this comment.
Function _read_password_from_pgpass refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator [×4] (merge-comparisons)
| 'could not match {} port numbers to {} hosts'.format( | ||
| len(port), len(hosts))) | ||
| f'could not match {len(port)} port numbers to {len(hosts)} hosts' | ||
| ) |
There was a problem hiding this comment.
Function _validate_port_spec refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| if ',' in hostlist: | ||
| # A comma-separated list of host addresses. | ||
| hostspecs = hostlist.split(',') | ||
| else: | ||
| hostspecs = [hostlist] | ||
|
|
||
| hostspecs = hostlist.split(',') if ',' in hostlist else [hostlist] | ||
| hosts = [] | ||
| hostlist_ports = [] | ||
|
|
||
| if not port: | ||
| portspec = os.environ.get('PGPORT') | ||
| if portspec: | ||
| if portspec := os.environ.get('PGPORT'): |
There was a problem hiding this comment.
Function _parse_hostlist refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Use named expression to simplify assignment and conditional [×2] (
use-named-expression) - Replace m.group(x) with m[x] for re.Match objects [×2] (
use-getitem-for-re-match-groups) - Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
This removes the following comments ( why? ):
# IPv6 address
# A comma-separated list of host addresses.
| tabname = utils._quote_ident(schema_name) + '.' + tabname | ||
| tabname = f'{utils._quote_ident(schema_name)}.{tabname}' | ||
|
|
||
| if columns: | ||
| col_list = ', '.join(utils._quote_ident(c) for c in columns) | ||
| cols = '({})'.format(col_list) | ||
| cols = f'({col_list})' |
There was a problem hiding this comment.
Function Connection.copy_records_to_table refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation) - Replace call to format with f-string (
use-fstring-for-formatting)
| opts.append('{} {}'.format(k.upper(), v)) | ||
| opts.append(f'{k.upper()} {v}') | ||
|
|
||
| if opts: | ||
| return '(' + ', '.join(opts) + ')' | ||
| else: | ||
| return '' | ||
| return '(' + ', '.join(opts) + ')' if opts else '' |
There was a problem hiding this comment.
Function Connection._format_copy_opts refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting) - Replace if statement with if expression (
assign-if-exp)
| 'cannot use custom codec on non-scalar type {}.{}'.format( | ||
| schema, typename)) | ||
| f'cannot use custom codec on non-scalar type {schema}.{typename}' | ||
| ) |
There was a problem hiding this comment.
Function Connection.set_type_codec refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| 'cannot alias non-scalar type {}.{}'.format( | ||
| schema, typename)) | ||
| f'cannot alias non-scalar type {schema}.{typename}' | ||
| ) |
There was a problem hiding this comment.
Function Connection.set_builtin_type_codec refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| if self._proxy is None: | ||
| con_ref = self | ||
| else: | ||
| # `_proxy` is not None when the connection is a member | ||
| # of a connection pool. Which means that the user is working | ||
| # with a `PoolConnectionProxy` instance, and expects to see it | ||
| # (and not the actual Connection) in their event callbacks. | ||
| con_ref = self._proxy | ||
| return con_ref | ||
| return self if self._proxy is None else self._proxy |
There was a problem hiding this comment.
Function Connection._unwrap refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# with a `PoolConnectionProxy` instance, and expects to see it
# `_proxy` is not None when the connection is a member
# (and not the actual Connection) in their event callbacks.
# of a connection pool. Which means that the user is working
| elif hasattr(connection_settings, 'crdb_version'): | ||
| elif hasattr(connection_settings, 'crdb_version') or hasattr( | ||
| connection_settings, 'crate_version' | ||
| ): | ||
| # CockroachDB detected. | ||
| advisory_locks = False | ||
| notifications = False | ||
| plpgsql = False | ||
| sql_reset = False | ||
| sql_close_all = False | ||
| elif hasattr(connection_settings, 'crate_version'): | ||
| # CrateDB detected. |
There was a problem hiding this comment.
Function _detect_server_capabilities refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks) - Remove redundant conditional (
remove-redundant-if)
This removes the following comments ( why? ):
# CrateDB detected.
| formatted = [] | ||
|
|
||
| for i, context in enumerate(self.__unhandled_exceptions): | ||
| formatted.append(self._format_loop_exception(context, i + 1)) | ||
| formatted = [ | ||
| self._format_loop_exception(context, i + 1) | ||
| for i, context in enumerate(self.__unhandled_exceptions) | ||
| ] |
There was a problem hiding this comment.
Function TestCase.tearDown refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| value = 'Object created at (most recent call last):\n' | ||
| value += tb.rstrip() | ||
| value = 'Object created at (most recent call last):\n' + tb.rstrip() | ||
| else: | ||
| try: | ||
| value = repr(value) | ||
| except Exception as ex: | ||
| value = ('Exception in __repr__ {!r}; ' | ||
| 'value type: {!r}'.format(ex, type(value))) | ||
| lines.append('[{}]: {}\n\n'.format(key, value)) | ||
| lines.append(f'[{key}]: {value}\n\n') |
There was a problem hiding this comment.
Function TestCase._format_loop_exception refactored with the following changes:
- Replace assignment and augmented assignment with single assignment (
merge-assign-and-aug-assign) - Replace call to format with f-string (
use-fstring-for-formatting)
| if not initdb_options: | ||
| initdb_options = {} | ||
| else: | ||
| initdb_options = dict(initdb_options) | ||
|
|
||
| initdb_options = dict(initdb_options) if initdb_options else {} |
There was a problem hiding this comment.
Function _get_initdb_options refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Swap if/else branches of if expression to remove negation (
swap-if-expression)
| pg_host = os.environ.get('PGHOST') | ||
| if pg_host: | ||
| if pg_host := os.environ.get('PGHOST'): |
There was a problem hiding this comment.
Function _init_default_cluster refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| drop_script.append('DROP ROLE {}_user;'.format(username)) | ||
| drop_script.append(f'DROP ROLE {username}_user;') |
There was a problem hiding this comment.
Function TestAuthentication.tearDown refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| for tried in range(3): | ||
| try: | ||
| for _ in range(3): | ||
| with contextlib.suppress(asyncpg.ConnectionDoesNotExistError): | ||
| return await self.connect(**kwargs) | ||
| except asyncpg.ConnectionDoesNotExistError: | ||
| pass | ||
|
|
There was a problem hiding this comment.
Function TestAuthentication._try_connect refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Use
contextlib'ssuppressmethod to silence an error (use-contextlib-suppress)
| old_vals = {} | ||
| for key in kwargs: | ||
| if key in os.environ: | ||
| old_vals[key] = os.environ[key] | ||
|
|
||
| old_vals = {key: os.environ[key] for key in kwargs if key in os.environ} |
There was a problem hiding this comment.
Function TestConnectParams.environ refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension)
| test_env.update(env) | ||
| test_env |= env |
There was a problem hiding this comment.
Function TestConnectParams.run_testcase refactored with the following changes:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union) - Replace call to format with f-string (
use-fstring-for-formatting)
| self.run_testcase({ | ||
| 'dsn': 'postgres://user@abc/db?passfile={}'.format( | ||
| passfile.name), | ||
| 'result': ( | ||
| [('abc', 5432)], | ||
| { | ||
| 'password': 'password from pgpass for user@abc', | ||
| 'user': 'user', | ||
| 'database': 'db', | ||
| } | ||
| ) | ||
| }) | ||
| self.run_testcase( | ||
| { | ||
| 'dsn': f'postgres://user@abc/db?passfile={passfile.name}', | ||
| 'result': ( | ||
| [('abc', 5432)], | ||
| { | ||
| 'password': 'password from pgpass for user@abc', | ||
| 'user': 'user', | ||
| 'database': 'db', | ||
| }, | ||
| ), | ||
| } | ||
| ) |
There was a problem hiding this comment.
Function TestConnectParams.test_connect_pgpass_regular refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| dsn='postgresql://foo/?sslmode=' + sslmode, | ||
| dsn=f'postgresql://foo/?sslmode={sslmode}', | ||
| user='postgres', | ||
| database='postgres', | ||
| host='localhost') | ||
| host='localhost', | ||
| ) |
There was a problem hiding this comment.
Function TestConnection.test_connection_sslmode_no_ssl_server refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| create_script = [] | ||
| create_script.append('CREATE ROLE ssl_user WITH LOGIN;') | ||
|
|
||
| create_script = ['CREATE ROLE ssl_user WITH LOGIN;'] |
There was a problem hiding this comment.
Function BaseTestSSLConnection.setUp refactored with the following changes:
- Merge append into list declaration (
merge-list-append)
| drop_script = [] | ||
| drop_script.append('DROP ROLE ssl_user;') | ||
| drop_script = ['DROP ROLE ssl_user;'] |
There was a problem hiding this comment.
Function BaseTestSSLConnection.tearDown refactored with the following changes:
- Merge append into list declaration (
merge-list-append)
| dsn='postgresql://foo/postgres?sslmode=' + sslmode, | ||
| dsn=f'postgresql://foo/postgres?sslmode={sslmode}', | ||
| host=host, | ||
| user='ssl_user') | ||
| user='ssl_user', | ||
| ) |
There was a problem hiding this comment.
Function TestSSLConnection.test_ssl_connection_sslmode refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| dsn = 'postgres://ssl_user@localhost/postgres?' + params_str | ||
| dsn = f'postgres://ssl_user@localhost/postgres?{params_str}' | ||
| await self._test_works(dsn=dsn) | ||
|
|
||
| params['sslkey'] = CLIENT_SSL_PROTECTED_KEY_FILE | ||
| params['sslpassword'] = 'secRet' | ||
| params_str = urllib.parse.urlencode(params) | ||
| dsn = 'postgres://ssl_user@localhost/postgres?' + params_str | ||
| dsn = f'postgres://ssl_user@localhost/postgres?{params_str}' |
There was a problem hiding this comment.
Function TestClientSSLConnection.test_ssl_connection_client_auth_dsn refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| await self._test_works(dsn=dsn + '&sslpassword=secRet') | ||
| await self._test_works(dsn=f'{dsn}&sslpassword=secRet') |
There was a problem hiding this comment.
Function TestClientSSLConnection.test_ssl_connection_client_auth_env refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| await self._test_works(dsn=dsn + '&sslpassword=secRet') | ||
| await self._test_works(dsn=f'{dsn}&sslpassword=secRet') |
There was a problem hiding this comment.
Function TestClientSSLConnection.test_ssl_connection_client_auth_dot_postgresql refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| dsn='postgresql://foo/postgres?sslmode=' + sslmode, | ||
| dsn=f'postgresql://foo/postgres?sslmode={sslmode}', | ||
| host=host, | ||
| user='ssl_user') | ||
| user='ssl_user', | ||
| ) |
There was a problem hiding this comment.
Function TestNoSSLConnection.test_nossl_connection_sslmode refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
Pull Request #2 refactored by Sourcery.
If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
target_session_attrbranch, then run:Help us improve this pull request!