Skip to content

Commit

Permalink
Bump linters and fix resulting flakes (#6833)
Browse files Browse the repository at this point in the history
  • Loading branch information
elprans authored Feb 13, 2024
1 parent 94aa456 commit 658bf82
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 97 deletions.
2 changes: 1 addition & 1 deletion edb/common/parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def __class_getitem__(

if not all(isinstance(param, type) for param in type_params):
if all(
type(param) == TypeVar # type: ignore[comparison-overlap]
type(param) is TypeVar # type: ignore[comparison-overlap]
for param in type_params
):
# All parameters are type variables: return the regular generic
Expand Down
3 changes: 2 additions & 1 deletion edb/common/signalctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def __exit__(self, exc_type, exc_val, exc_tb):
handler.cancel()
if self._waiters:
warnings.warn(
"SignalController exited before wait_for() completed."
"SignalController exited before wait_for() completed.",
stacklevel=1,
)
registry = self._registry[self._loop]
for signal in self._signals:
Expand Down
18 changes: 8 additions & 10 deletions edb/edgeql/compiler/config_desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _describe_config_inner(

ptr_card = p.get_cardinality(schema)
mult = ptr_card.is_multi()
psource = f'{config_object_name}{cast}.{ qlquote.quote_ident(pn) }'
psource = f'{config_object_name}{cast}.{qlquote.quote_ident(pn)}'
if isinstance(ptype, s_objtypes.ObjectType):
item = textwrap.indent(
_render_config_object(
Expand Down Expand Up @@ -249,13 +249,11 @@ def _render_config_redacted(
if level == 1:
return (
f"'CONFIGURE {scope.to_edgeql()} "
f"SET { qlquote.quote_ident(name) } := {{}}; # REDACTED\\n'"
f"SET {qlquote.quote_ident(name)} := {{}}; # REDACTED\\n'"
)
else:
indent = ' ' * (4 * (level - 1))
return (
f"'{indent}{ qlquote.quote_ident(name) } := {{}}, # REDACTED'"
)
return f"'{indent}{qlquote.quote_ident(name)} := {{}}, # REDACTED'"


def _render_config_set(
Expand All @@ -273,14 +271,14 @@ def _render_config_set(
if level == 1:
return (
f"'CONFIGURE {scope.to_edgeql()} "
f"SET { qlquote.quote_ident(name) } := {{' ++ "
f"SET {qlquote.quote_ident(name)} := {{' ++ "
f"array_join(array_agg((select _ := {v} order by _)), ', ') "
f"++ '}};\\n'"
)
else:
indent = ' ' * (4 * (level - 1))
return (
f"'{indent}{ qlquote.quote_ident(name) } := {{' ++ "
f"'{indent}{qlquote.quote_ident(name)} := {{' ++ "
f"array_join(array_agg((SELECT _ := {v} ORDER BY _)), ', ') "
f"++ '}},'"
)
Expand All @@ -301,11 +299,11 @@ def _render_config_scalar(
if level == 1:
return (
f"'CONFIGURE {scope.to_edgeql()} "
f"SET { qlquote.quote_ident(name) } := ' ++ {v} ++ ';\\n'"
f"SET {qlquote.quote_ident(name)} := ' ++ {v} ++ ';\\n'"
)
else:
indent = ' ' * (4 * (level - 1))
return f"'{indent}{ qlquote.quote_ident(name) } := ' ++ {v} ++ ','"
return f"'{indent}{qlquote.quote_ident(name)} := ' ++ {v} ++ ','"


def _render_config_object(
Expand Down Expand Up @@ -406,7 +404,7 @@ def _describe_config_object(

ptr_card = p.get_cardinality(schema)
mult = ptr_card.is_multi()
psource = f'item.{ qlquote.quote_ident(pn) }'
psource = f'item.{qlquote.quote_ident(pn)}'

if isinstance(ptype, s_objtypes.ObjectType):
rval = textwrap.indent(
Expand Down
4 changes: 2 additions & 2 deletions edb/pgsql/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def escape_sq(s):
return "E'" + escape_sq(string) + "'"


def quote_literal(string):
def quote_literal(string: str) -> str:
return "'" + string.replace("'", "''") + "'"


Expand Down Expand Up @@ -112,7 +112,7 @@ def qname(*parts: str | pgast.Star, column: bool=False) -> str:
return '.'.join([quote_ident(q, column=column) for q in parts])


def quote_type(type_: Tuple[str, ...] | str):
def quote_type(type_: Tuple[str, ...] | str) -> str:
if isinstance(type_, tuple):
first = qname(*type_[:-1]) + '.' if len(type_) > 1 else ''
last = type_[-1]
Expand Down
2 changes: 1 addition & 1 deletion edb/pgsql/dbops/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def code(self, block: base.PLBlock) -> str:

if any(isinstance(e, base.PLExpression) for e in elems):
# Dynamic declaration
elem_chunks = []
elem_chunks: list[base.PLExpression | str] = []
for e in elems:
if isinstance(e, base.PLExpression):
elem_chunks.append(e)
Expand Down
71 changes: 23 additions & 48 deletions edb/pgsql/metaschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
}


def qtl(t: tuple[str, ...]) -> str:
"""Quote type literal"""
return ql(f'{t[0]}.{t[1]}') if len(t) == 2 else ql(f'pg_catalog.{t[0]}')


class PGConnection(Protocol):

async def sql_execute(
Expand Down Expand Up @@ -2706,9 +2711,9 @@ def __init__(self, schema: s_schema.Schema) -> None:
SELECT
coalesce(string_agg(
CASE WHEN
role.{qi(name_col)} = { ql(defines.EDGEDB_SUPERUSER) } THEN
role.{qi(name_col)} = {ql(defines.EDGEDB_SUPERUSER)} THEN
NULLIF(concat(
'ALTER ROLE { qi_superuser } {{',
'ALTER ROLE {qi_superuser} {{',
NULLIF((SELECT
concat(
' EXTENDING ',
Expand All @@ -2729,7 +2734,7 @@ def __init__(self, schema: s_schema.Schema) -> None:
';')
ELSE '' END,
'}};'
), 'ALTER ROLE { qi_superuser } {{}};')
), 'ALTER ROLE {qi_superuser} {{}};')
ELSE
concat(
'CREATE SUPERUSER ROLE ',
Expand Down Expand Up @@ -3802,7 +3807,7 @@ def __init__(self, config_spec: edbconfig.Spec) -> None:
backend_settings[setting_name] = setting.backend_setting

variants_list = []
for setting_name in backend_settings:
for setting_name, backend_setting_name in backend_settings.items():
setting = config_spec[setting_name]

valql = '"value"->>0'
Expand All @@ -3818,7 +3823,7 @@ def __init__(self, config_spec: edbconfig.Spec) -> None:
WHEN "name" = {ql(setting_name)}
THEN
pg_catalog.set_config(
{ql(setting.backend_setting)}::text,
{ql(backend_setting_name)}::text,
{valql},
false
)
Expand Down Expand Up @@ -3938,18 +3943,10 @@ def __init__(self) -> None:
class GetBaseScalarTypeMap(dbops.Function):
"""Return a map of base EdgeDB scalar type ids to Postgres type names."""

text = f'''
VALUES
{", ".join(
f"""(
{ql(str(k))}::uuid,
{
ql(f'{v[0]}.{v[1]}') if len(v) == 2
else ql(f'pg_catalog.{v[0]}')
}
)"""
for k, v in types.base_type_name_map.items())}
'''
text = "VALUES" + ", ".join(
f"({ql(str(k))}::uuid, {qtl(v)})"
for k, v in types.base_type_name_map.items()
)

def __init__(self) -> None:
super().__init__(
Expand All @@ -3965,21 +3962,10 @@ def __init__(self) -> None:
class GetTypeToRangeNameMap(dbops.Function):
"""Return a map of type names to the name of the associated range type"""

text = f'''
VALUES
{", ".join(
f"""(
{
ql(f'{k[0]}.{k[1]}') if len(k) == 2
else ql(f'pg_catalog.{k[0]}')
},
{
ql(f'{v[0]}.{v[1]}') if len(v) == 2
else ql(f'pg_catalog.{v[0]}')
}
)"""
for k, v in types.type_to_range_name_map.items())}
'''
text = f"VALUES" + ", ".join(
f"({qtl(k)}, {qtl(v)})"
for k, v in types.type_to_range_name_map.items()
)

def __init__(self) -> None:
super().__init__(
Expand All @@ -3995,21 +3981,10 @@ def __init__(self) -> None:
class GetTypeToMultiRangeNameMap(dbops.Function):
"Return a map of type names to the name of the associated multirange type"

text = f'''
VALUES
{", ".join(
f"""(
{
ql(f'{k[0]}.{k[1]}') if len(k) == 2
else ql(f'pg_catalog.{k[0]}')
},
{
ql(f'{v[0]}.{v[1]}') if len(v) == 2
else ql(f'pg_catalog.{v[0]}')
}
)"""
for k, v in types.type_to_multirange_name_map.items())}
'''
text = f"VALUES" + ", ".join(
f"({qtl(k)}, {qtl(v)})"
for k, v in types.type_to_multirange_name_map.items()
)

def __init__(self) -> None:
super().__init__(
Expand Down Expand Up @@ -6937,7 +6912,7 @@ def _generate_config_type_view(
source0 = f'''
(SELECT
(SELECT jsonb_object_agg(
substr(name, {len(cfg_name)+3}), value) AS val
substr(name, {len(cfg_name) + 3}), value) AS val
FROM edgedb._read_sys_config(
NULL, scope::edgedb._sys_config_source_t) cfg
WHERE name LIKE {ql(escaped_name + '%')}
Expand Down
2 changes: 2 additions & 0 deletions edb/pgsql/resolver/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ def to_regclass(reg_class_name: str, ctx: Context) -> pgast.BaseExpr:
name = (ctx.options.search_path[0], name[0])

namespace, rel_name = name
assert isinstance(namespace, str)
assert isinstance(rel_name, str)

# A bit hacky to parse SQL here, but I don't want to construct pgast
[stmt] = pgparser.parse(
Expand Down
2 changes: 1 addition & 1 deletion edb/pgsql/schemamech.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ def enforce_ops(self) -> dbops.CommandGroup:
"schema" => '{schemaname}',
detail => {detail}
)
FROM {common.qname(schemaname, tablename+"_t")} AS OLD
FROM {common.qname(schemaname, tablename + "_t")} AS OLD
CROSS JOIN {common.qname(*real_tablename)} AS NEW
WHERE {old_expr} = {new_expr} and OLD.{key} != NEW.{key}
{except_part}
Expand Down
2 changes: 1 addition & 1 deletion edb/schema/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ def compare_field_value(
if (
our_value is not None
and their_value is not None
and type(our_value) == type(their_value)
and type(our_value) is type(their_value)
):
comparator = getattr(type(our_value), 'compare_values', None)
else:
Expand Down
4 changes: 2 additions & 2 deletions edb/schema/ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def maybe_attach_to_preceding(

allowed_ops = []
create_cmd_t = ancestor_op.get_other_command_class(sd.CreateObject)
if type(ancestor_op) != create_cmd_t:
if type(ancestor_op) is not create_cmd_t:
allowed_ops.append(create_cmd_t)
allowed_ops.append(type(ancestor_op))

Expand Down Expand Up @@ -700,7 +700,7 @@ def write_ref_deps(
# new one is created)
if not isinstance(ref, s_expraliases.Alias):
deps.add(('alter', ref_name_str))
if type(ref) == type(obj):
if type(ref) is type(obj):
deps.add(('rebase', ref_name_str))

# The deletion of any implicit ancestors needs to come after
Expand Down
13 changes: 13 additions & 0 deletions edb/server/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,12 +1027,14 @@ def parse_args(**kwargs: Any):
"The `--echo-runtime-info` option is deprecated, use "
"`--emit-server-status` instead.",
DeprecationWarning,
stacklevel=2,
)

if kwargs['bootstrap']:
warnings.warn(
"Option `--bootstrap` is deprecated, use `--bootstrap-only`",
DeprecationWarning,
stacklevel=2,
)
kwargs['bootstrap_only'] = True

Expand All @@ -1045,12 +1047,14 @@ def parse_args(**kwargs: Any):
" Role `edgedb` is always created and"
" no role named after unix user is created any more.",
DeprecationWarning,
stacklevel=2,
)
else:
warnings.warn(
"Option `--default-database-user` is deprecated."
" Please create the role explicitly.",
DeprecationWarning,
stacklevel=2,
)

if kwargs['default_database']:
Expand All @@ -1060,19 +1064,22 @@ def parse_args(**kwargs: Any):
" Database `edgedb` is always created and"
" no database named after unix user is created any more.",
DeprecationWarning,
stacklevel=2,
)
else:
warnings.warn(
"Option `--default-database` is deprecated."
" Please create the database explicitly.",
DeprecationWarning,
stacklevel=2,
)

if kwargs['auto_shutdown']:
warnings.warn(
"The `--auto-shutdown` option is deprecated, use "
"`--auto-shutdown-after` instead.",
DeprecationWarning,
stacklevel=2,
)
if kwargs['auto_shutdown_after'] < 0:
kwargs['auto_shutdown_after'] = 0
Expand All @@ -1084,6 +1091,7 @@ def parse_args(**kwargs: Any):
"The `--postgres-dsn` option is deprecated, use "
"`--backend-dsn` instead.",
DeprecationWarning,
stacklevel=2,
)
if not kwargs['backend_dsn']:
kwargs['backend_dsn'] = kwargs['postgres_dsn']
Expand All @@ -1095,6 +1103,7 @@ def parse_args(**kwargs: Any):
"The `--generate-self-signed-cert` option is deprecated, use "
"`--tls-cert-mode=generate_self_signed` instead.",
DeprecationWarning,
stacklevel=2,
)
if kwargs['tls_cert_mode'] == 'default':
kwargs['tls_cert_mode'] = 'generate_self_signed'
Expand All @@ -1115,6 +1124,7 @@ def parse_args(**kwargs: Any):
"deprecated. Use EDGEDB_SERVER_BINARY_ENDPOINT_SECURITY "
"instead.",
DeprecationWarning,
stacklevel=2,
)
kwargs['binary_endpoint_security'] = 'optional'

Expand All @@ -1132,6 +1142,7 @@ def parse_args(**kwargs: Any):
"deprecated. Use EDGEDB_SERVER_BINARY_ENDPOINT_SECURITY "
"instead.",
DeprecationWarning,
stacklevel=2,
)
kwargs['http_endpoint_security'] = 'optional'

Expand Down Expand Up @@ -1324,6 +1335,7 @@ def parse_args(**kwargs: Any):
"The `--bootstrap-script` option is deprecated, use "
"`--bootstrap-command-file` instead.",
DeprecationWarning,
stacklevel=2,
)
kwargs['bootstrap_command_file'] = kwargs['bootstrap_script']
else:
Expand All @@ -1332,6 +1344,7 @@ def parse_args(**kwargs: Any):
"were specified, but are mutually exclusive. "
"Ignoring the deprecated `--bootstrap-script` option.",
DeprecationWarning,
stacklevel=2,
)

del kwargs['bootstrap_script']
Expand Down
Loading

0 comments on commit 658bf82

Please sign in to comment.