From: Federico Caselli Date: Thu, 8 Jun 2023 19:42:44 +0000 (+0200) Subject: Update black X-Git-Tag: rel_1_11_2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79738c9e971d4bbe6f4845a54fd0f972d15e1035;p=thirdparty%2Fsqlalchemy%2Falembic.git Update black Change-Id: I836b9a322819c07ec202fdcca4fd52818b994bff --- diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c4397b96..8d68141e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,19 +2,19 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/python/black - rev: 22.3.0 + rev: 23.3.0 hooks: - id: black - repo: https://github.com/sqlalchemyorg/zimports - rev: v0.4.0 + rev: v0.6.0 hooks: - id: zimports args: - --keep-unused-type-checking - repo: https://github.com/pycqa/flake8 - rev: 3.9.2 + rev: 6.0.0 hooks: - id: flake8 additional_dependencies: diff --git a/alembic/autogenerate/api.py b/alembic/autogenerate/api.py index c4ec5c1c..064bca9f 100644 --- a/alembic/autogenerate/api.py +++ b/alembic/autogenerate/api.py @@ -331,7 +331,6 @@ class AutogenContext: opts: Optional[dict] = None, autogenerate: bool = True, ) -> None: - if ( autogenerate and migration_context is not None @@ -431,7 +430,6 @@ class AutogenContext: parent_names["schema_qualified_table_name"] = table_name for fn in self._name_filters: - if not fn(name, type_, parent_names): return False else: diff --git a/alembic/autogenerate/compare.py b/alembic/autogenerate/compare.py index 031d683b..db32a6a4 100644 --- a/alembic/autogenerate/compare.py +++ b/alembic/autogenerate/compare.py @@ -66,7 +66,6 @@ comparators = util.Dispatcher(uselist=True) def _produce_net_changes( autogen_context: AutogenContext, upgrade_ops: UpgradeOps ) -> None: - connection = autogen_context.connection assert connection is not None include_schemas = autogen_context.opts.get("include_schemas", False) @@ -145,7 +144,6 @@ def _compare_tables( upgrade_ops: UpgradeOps, autogen_context: AutogenContext, ) -> None: - default_schema = inspector.bind.dialect.default_schema_name # tables coming from the connection will not have "schema" @@ -214,7 +212,6 @@ def _compare_tables( ) sqla_compat._reflect_table(inspector, t) if autogen_context.run_object_filters(t, tname, "table", True, None): - modify_table_ops = ops.ModifyTableOps(tname, [], schema=s) comparators.dispatch("table")( @@ -255,7 +252,6 @@ def _compare_tables( if autogen_context.run_object_filters( metadata_table, tname, "table", False, conn_table ): - modify_table_ops = ops.ModifyTableOps(tname, [], schema=s) with _compare_columns( s, @@ -266,7 +262,6 @@ def _compare_tables( autogen_context, inspector, ): - comparators.dispatch("table")( autogen_context, modify_table_ops, @@ -534,7 +529,6 @@ def _compare_indexes_and_uniques( conn_table: Optional[Table], metadata_table: Optional[Table], ) -> None: - inspector = autogen_context.inspector is_create_table = conn_table is None is_drop_table = metadata_table is None @@ -913,7 +907,6 @@ def _correct_for_uq_duplicates_uix( _uq_constraint_sig(uqs_dupe_indexes[overlap]).sig not in unnamed_metadata_uqs ): - conn_unique_constraints.discard(uqs_dupe_indexes[overlap]) elif overlap not in metadata_ix_names: conn_indexes.discard(conn_ix_names[overlap]) @@ -929,7 +922,6 @@ def _compare_nullable( conn_col: Column[Any], metadata_col: Column[Any], ) -> None: - metadata_col_nullable = metadata_col.nullable conn_col_nullable = conn_col.nullable alter_column_op.existing_nullable = conn_col_nullable @@ -971,7 +963,6 @@ def _setup_autoincrement( conn_col: Column[Any], metadata_col: Column[Any], ) -> None: - if metadata_col.table._autoincrement_column is metadata_col: alter_column_op.kw["autoincrement"] = True elif metadata_col.autoincrement is True: @@ -990,7 +981,6 @@ def _compare_type( conn_col: Column[Any], metadata_col: Column[Any], ) -> None: - conn_type = conn_col.type alter_column_op.existing_type = conn_type metadata_type = metadata_col.type @@ -1027,7 +1017,6 @@ def _compare_type( def _render_server_default_for_compare( metadata_default: Optional[Any], autogen_context: AutogenContext ) -> Optional[str]: - if isinstance(metadata_default, sa_schema.DefaultClause): if isinstance(metadata_default.arg, str): metadata_default = metadata_default.arg @@ -1129,7 +1118,6 @@ def _compare_server_default( conn_col: Column[Any], metadata_col: Column[Any], ) -> Optional[bool]: - metadata_default = metadata_col.server_default conn_col_default = conn_col.server_default if conn_col_default is None and metadata_default is None: @@ -1218,7 +1206,6 @@ def _compare_column_comment( conn_col: Column[Any], metadata_col: Column[Any], ) -> Optional[Literal[False]]: - assert autogen_context.dialect is not None if not autogen_context.dialect.supports_comments: return None @@ -1246,7 +1233,6 @@ def _compare_foreign_keys( conn_table: Optional[Table], metadata_table: Optional[Table], ) -> None: - # if we're doing CREATE TABLE, all FKs are created # inline within the table def if conn_table is None or metadata_table is None: @@ -1366,7 +1352,6 @@ def _compare_table_comment( conn_table: Optional[Table], metadata_table: Optional[Table], ) -> None: - assert autogen_context.dialect is not None if not autogen_context.dialect.supports_comments: return diff --git a/alembic/autogenerate/render.py b/alembic/autogenerate/render.py index 00d1d2fe..215af8ce 100644 --- a/alembic/autogenerate/render.py +++ b/alembic/autogenerate/render.py @@ -94,7 +94,6 @@ def _render_cmd_body( op_container: ops.OpContainer, autogen_context: AutogenContext, ) -> str: - buf = StringIO() printer = PythonPrinter(buf) @@ -165,7 +164,6 @@ def _render_modify_table( def _render_create_table_comment( autogen_context: AutogenContext, op: ops.CreateTableCommentOp ) -> str: - templ = ( "{prefix}create_table_comment(\n" "{indent}'{tname}',\n" @@ -190,7 +188,6 @@ def _render_create_table_comment( def _render_drop_table_comment( autogen_context: AutogenContext, op: ops.DropTableCommentOp ) -> str: - templ = ( "{prefix}drop_table_comment(\n" "{indent}'{tname}',\n" @@ -362,7 +359,6 @@ def _add_unique_constraint( def _add_fk_constraint( autogen_context: AutogenContext, op: ops.CreateForeignKeyOp ) -> str: - args = [repr(_render_gen_name(autogen_context, op.constraint_name))] if not autogen_context._has_batch: args.append(repr(_ident(op.source_table))) @@ -411,7 +407,6 @@ def _add_check_constraint(constraint, autogen_context): def _drop_constraint( autogen_context: AutogenContext, op: ops.DropConstraintOp ) -> str: - if autogen_context._has_batch: template = "%(prefix)sdrop_constraint" "(%(name)r, type_=%(type)r)" else: @@ -432,7 +427,6 @@ def _drop_constraint( @renderers.dispatch_for(ops.AddColumnOp) def _add_column(autogen_context: AutogenContext, op: ops.AddColumnOp) -> str: - schema, tname, column = op.schema, op.table_name, op.column if autogen_context._has_batch: template = "%(prefix)sadd_column(%(column)s)" @@ -452,7 +446,6 @@ def _add_column(autogen_context: AutogenContext, op: ops.AddColumnOp) -> str: @renderers.dispatch_for(ops.DropColumnOp) def _drop_column(autogen_context: AutogenContext, op: ops.DropColumnOp) -> str: - schema, tname, column_name = op.schema, op.table_name, op.column_name if autogen_context._has_batch: @@ -476,7 +469,6 @@ def _drop_column(autogen_context: AutogenContext, op: ops.DropColumnOp) -> str: def _alter_column( autogen_context: AutogenContext, op: ops.AlterColumnOp ) -> str: - tname = op.table_name cname = op.column_name server_default = op.modify_server_default @@ -566,7 +558,6 @@ def _render_potential_expr( is_server_default: bool = False, ) -> str: if isinstance(value, sql.ClauseElement): - if wrap_in_text: template = "%(prefix)stext(%(sql)r)" else: @@ -675,7 +666,6 @@ def _render_column( opts: List[Tuple[str, Any]] = [] if column.server_default: - rendered = _render_server_default( # type:ignore[assignment] column.server_default, autogen_context ) @@ -984,7 +974,6 @@ def _fk_colspec( def _populate_render_fk_opts( constraint: ForeignKeyConstraint, opts: List[Tuple[str, str]] ) -> None: - if constraint.onupdate: opts.append(("onupdate", repr(constraint.onupdate))) if constraint.ondelete: diff --git a/alembic/command.py b/alembic/command.py index a015be39..f5e1ee06 100644 --- a/alembic/command.py +++ b/alembic/command.py @@ -494,7 +494,6 @@ def history( for sc in script.walk_revisions( base=base or "base", head=head or "heads" ): - if indicate_current: sc._db_current_indicator = sc.revision in currents diff --git a/alembic/config.py b/alembic/config.py index 1577ce9f..d01173cb 100644 --- a/alembic/config.py +++ b/alembic/config.py @@ -24,7 +24,6 @@ from .util import compat class Config: - r"""Represent an Alembic configuration. Within an ``env.py`` script, this is available @@ -563,7 +562,6 @@ class CommandLine: and fn.__name__[0] != "_" and fn.__module__ == "alembic.command" ): - spec = compat.inspect_getfullargspec(fn) if spec[3] is not None: positional = spec[0][1 : -len(spec[3])] diff --git a/alembic/ddl/impl.py b/alembic/ddl/impl.py index 03f134d5..726f1686 100644 --- a/alembic/ddl/impl.py +++ b/alembic/ddl/impl.py @@ -637,7 +637,6 @@ class DefaultImpl(metaclass=ImplMeta): return False def _compare_identity_default(self, metadata_identity, inspector_identity): - # ignored contains the attributes that were not considered # because assumed to their default values in the db. diff, ignored = _compare_identity_options( diff --git a/alembic/ddl/mssql.py b/alembic/ddl/mssql.py index 10c1a6b9..56dd12c3 100644 --- a/alembic/ddl/mssql.py +++ b/alembic/ddl/mssql.py @@ -98,7 +98,6 @@ class MSSQLImpl(DefaultImpl): existing_nullable: Optional[bool] = None, **kw: Any, ) -> None: - if nullable is not None: if type_ is not None: # the NULL/NOT NULL alter will handle @@ -231,9 +230,7 @@ class MSSQLImpl(DefaultImpl): rendered_metadata_default, rendered_inspector_default, ): - if rendered_metadata_default is not None: - rendered_metadata_default = re.sub( r"[\(\) \"\']", "", rendered_metadata_default ) diff --git a/alembic/ddl/mysql.py b/alembic/ddl/mysql.py index 5e66f538..32ced498 100644 --- a/alembic/ddl/mysql.py +++ b/alembic/ddl/mysql.py @@ -240,7 +240,6 @@ class MySQLImpl(DefaultImpl): metadata_unique_constraints, metadata_indexes, ): - # TODO: if SQLA 1.0, make use of "duplicates_index" # metadata removed = set() diff --git a/alembic/ddl/postgresql.py b/alembic/ddl/postgresql.py index e3ada908..c2d31062 100644 --- a/alembic/ddl/postgresql.py +++ b/alembic/ddl/postgresql.py @@ -90,7 +90,6 @@ class PostgresqlImpl(DefaultImpl): self._exec(CreateIndex(index)) def prep_table_for_batch(self, batch_impl, table): - for constraint in table.constraints: if ( constraint.name is not None @@ -157,7 +156,6 @@ class PostgresqlImpl(DefaultImpl): existing_autoincrement: Optional[bool] = None, **kw: Any, ) -> None: - using = kw.pop("postgresql_using", None) if using is not None and type_ is None: @@ -239,7 +237,6 @@ class PostgresqlImpl(DefaultImpl): metadata_unique_constraints, metadata_indexes, ): - doubled_constraints = { index for index in conn_indexes @@ -638,7 +635,6 @@ def _render_inline_exclude_constraint( def _postgresql_autogenerate_prefix(autogen_context: AutogenContext) -> str: - imports = autogen_context.imports if imports is not None: imports.add("from sqlalchemy.dialects import postgresql") diff --git a/alembic/ddl/sqlite.py b/alembic/ddl/sqlite.py index 67a1c284..c6186c60 100644 --- a/alembic/ddl/sqlite.py +++ b/alembic/ddl/sqlite.py @@ -100,7 +100,6 @@ class SQLiteImpl(DefaultImpl): rendered_metadata_default: Optional[str], rendered_inspector_default: Optional[str], ) -> bool: - if rendered_metadata_default is not None: rendered_metadata_default = re.sub( r"^\((.+)\)$", r"\1", rendered_metadata_default @@ -193,7 +192,6 @@ class SQLiteImpl(DefaultImpl): metadata_unique_constraints, metadata_indexes, ): - self._skip_functional_indexes(metadata_indexes, conn_indexes) diff --git a/alembic/operations/batch.py b/alembic/operations/batch.py index 5b6b5477..e4413dd3 100644 --- a/alembic/operations/batch.py +++ b/alembic/operations/batch.py @@ -337,7 +337,6 @@ class ApplyBatchImpl: for const in ( list(self.named_constraints.values()) + self.unnamed_constraints ): - const_columns = {c.key for c in _columns_for_constraint(const)} if not const_columns.issubset(self.column_transfers): diff --git a/alembic/operations/ops.py b/alembic/operations/ops.py index ae929fae..4d900121 100644 --- a/alembic/operations/ops.py +++ b/alembic/operations/ops.py @@ -176,7 +176,6 @@ class DropConstraintOp(MigrateOperation): ) def to_constraint(self) -> Constraint: - if self._reverse is not None: constraint = self._reverse.to_constraint() constraint.name = self.constraint_name @@ -397,7 +396,6 @@ class CreateUniqueConstraintOp(AddConstraintOp): def from_constraint( cls, constraint: Constraint ) -> CreateUniqueConstraintOp: - constraint_table = sqla_compat._table_for_constraint(constraint) uq_constraint = cast("UniqueConstraint", constraint) @@ -535,7 +533,6 @@ class CreateForeignKeyOp(AddConstraintOp): @classmethod def from_constraint(cls, constraint: Constraint) -> CreateForeignKeyOp: - fk_constraint = cast("ForeignKeyConstraint", constraint) kw: dict = {} if fk_constraint.onupdate: @@ -1758,7 +1755,6 @@ class AlterColumnOp(AlterTableOp): return False def reverse(self) -> AlterColumnOp: - kw = self.kw.copy() kw["existing_type"] = self.existing_type kw["existing_nullable"] = self.existing_nullable diff --git a/alembic/operations/toimpl.py b/alembic/operations/toimpl.py index add142de..72229c6c 100644 --- a/alembic/operations/toimpl.py +++ b/alembic/operations/toimpl.py @@ -14,7 +14,6 @@ if TYPE_CHECKING: def alter_column( operations: "Operations", operation: "ops.AlterColumnOp" ) -> None: - compiler = operations.impl.dialect.statement_compiler( operations.impl.dialect, None ) diff --git a/alembic/runtime/environment.py b/alembic/runtime/environment.py index acd5cd1e..e5dfa59e 100644 --- a/alembic/runtime/environment.py +++ b/alembic/runtime/environment.py @@ -25,7 +25,6 @@ from .. import util from ..operations import Operations if TYPE_CHECKING: - from sqlalchemy.engine import URL from sqlalchemy.engine.base import Connection from sqlalchemy.sql.elements import ClauseElement diff --git a/alembic/runtime/migration.py b/alembic/runtime/migration.py index 1715e8af..2c10ad59 100644 --- a/alembic/runtime/migration.py +++ b/alembic/runtime/migration.py @@ -522,7 +522,6 @@ class MigrationContext: if start_from_rev == "base": start_from_rev = None elif start_from_rev is not None and self.script: - start_from_rev = [ cast("Script", self.script.get_revision(sfr)).revision for sfr in util.to_list(start_from_rev) @@ -614,7 +613,6 @@ class MigrationContext: assert self._migrations_fn is not None for step in self._migrations_fn(heads, self): with self.begin_transaction(_per_migration=True): - if self.as_sql and not head_maintainer.heads: # for offline mode, include a CREATE TABLE from # the base @@ -733,7 +731,6 @@ class MigrationContext: rendered_metadata_default: Optional[str], rendered_column_default: Optional[str], ) -> bool: - if self._user_compare_server_default is False: return False @@ -1000,7 +997,6 @@ class MigrationInfo: class MigrationStep: - from_revisions_no_deps: Tuple[str, ...] to_revisions_no_deps: Tuple[str, ...] is_upgrade: bool diff --git a/alembic/script/base.py b/alembic/script/base.py index cf929c97..9894b4c3 100644 --- a/alembic/script/base.py +++ b/alembic/script/base.py @@ -479,7 +479,6 @@ class ScriptDirectory: multiple_heads="Multiple heads are present; please specify a " "single target revision" ): - heads_revs = self.get_revisions(heads) steps = [] @@ -502,7 +501,6 @@ class ScriptDirectory: dests = self.get_revisions(revision) or [None] for dest in dests: - if dest is None: # dest is 'base'. Return a "delete branch" migration # for all applicable heads. diff --git a/alembic/script/revision.py b/alembic/script/revision.py index 39152969..fe9ff616 100644 --- a/alembic/script/revision.py +++ b/alembic/script/revision.py @@ -336,7 +336,6 @@ class RevisionMap: and not parent._is_real_branch_point and not parent.is_merge_point ): - parent.branch_labels.update(revision.branch_labels) if parent.down_revision: parent = map_[parent.down_revision] @@ -813,7 +812,6 @@ class RevisionMap: omit_immediate_dependencies: bool = False, include_dependencies: bool = True, ) -> Iterator[Any]: - if omit_immediate_dependencies: def fn(rev): @@ -843,7 +841,6 @@ class RevisionMap: check: bool = False, include_dependencies: bool = True, ) -> Iterator[Revision]: - if include_dependencies: def fn(rev): @@ -945,7 +942,6 @@ class RevisionMap: current_candidate_idx = 0 while current_heads: - candidate = current_heads[current_candidate_idx] for check_head_index, ancestors in enumerate(ancestors_by_idx): diff --git a/alembic/script/write_hooks.py b/alembic/script/write_hooks.py index d37555d7..0e9ec40a 100644 --- a/alembic/script/write_hooks.py +++ b/alembic/script/write_hooks.py @@ -114,7 +114,6 @@ def _parse_cmdline_options(cmdline_options_str: str, path: str) -> List[str]: def console_scripts( path: str, options: dict, ignore_output: bool = False ) -> None: - try: entrypoint_name = options["entrypoint"] except KeyError as ke: diff --git a/alembic/testing/assertions.py b/alembic/testing/assertions.py index 1c24066b..ec9593b7 100644 --- a/alembic/testing/assertions.py +++ b/alembic/testing/assertions.py @@ -64,7 +64,6 @@ def assert_raises_message_context_ok( def _assert_raises( except_cls, callable_, args, kwargs, msg=None, check_context=False ): - with _expect_raises(except_cls, msg, check_context) as ec: callable_(*args, **kwargs) return ec.error @@ -104,7 +103,6 @@ def expect_raises_message(except_cls, msg, check_context=True): def eq_ignore_whitespace(a, b, msg=None): - a = re.sub(r"^\s+?|\n", "", a) a = re.sub(r" {2,}", " ", a) b = re.sub(r"^\s+?|\n", "", b) @@ -120,7 +118,6 @@ def _get_dialect(name): if name is None or name == "default": return default.DefaultDialect() else: - d = sqla_compat._create_url(name).get_dialect()() if name == "postgresql": diff --git a/alembic/testing/env.py b/alembic/testing/env.py index 79a4980f..5df7ef82 100644 --- a/alembic/testing/env.py +++ b/alembic/testing/env.py @@ -22,10 +22,8 @@ def _get_staging_directory(): def staging_env(create=True, template="generic", sourceless=False): - cfg = _testing_config() if create: - path = os.path.join(_get_staging_directory(), "scripts") assert not os.path.exists(path), ( "staging directory %s already exists; poor cleanup?" % path @@ -284,7 +282,6 @@ def write_script( def make_sourceless(path, style): - import py_compile py_compile.compile(path) diff --git a/alembic/testing/fixtures.py b/alembic/testing/fixtures.py index 65f3a0a9..4b83a745 100644 --- a/alembic/testing/fixtures.py +++ b/alembic/testing/fixtures.py @@ -134,7 +134,6 @@ def op_fixture( literal_binds=False, native_boolean=None, ): - opts = {} if naming_convention: opts["target_metadata"] = MetaData(naming_convention=naming_convention) @@ -217,7 +216,6 @@ def op_fixture( class AlterColRoundTripFixture: - # since these tests are about syntax, use more recent SQLAlchemy as some of # the type / server default compare logic might not work on older # SQLAlchemy versions as seems to be the case for SQLAlchemy 1.1 on Oracle diff --git a/alembic/testing/suite/_autogen_fixtures.py b/alembic/testing/suite/_autogen_fixtures.py index e09fbfe5..d838ebef 100644 --- a/alembic/testing/suite/_autogen_fixtures.py +++ b/alembic/testing/suite/_autogen_fixtures.py @@ -279,7 +279,6 @@ class AutogenFixtureTest(_ComparesFKs): return_ops=False, max_identifier_length=None, ): - if max_identifier_length: dialect = self.bind.dialect existing_length = dialect.max_identifier_length diff --git a/alembic/util/langhelpers.py b/alembic/util/langhelpers.py index f62bc193..34d48bc6 100644 --- a/alembic/util/langhelpers.py +++ b/alembic/util/langhelpers.py @@ -243,7 +243,6 @@ class Dispatcher: return decorate def dispatch(self, obj: Any, qualifier: str = "default") -> Any: - if isinstance(obj, str): targets: Sequence = [obj] elif isinstance(obj, type): diff --git a/alembic/util/pyfiles.py b/alembic/util/pyfiles.py index 75350047..e7576731 100644 --- a/alembic/util/pyfiles.py +++ b/alembic/util/pyfiles.py @@ -49,7 +49,6 @@ def coerce_resource_to_filename(fname: str) -> str: """ if not os.path.isabs(fname) and ":" in fname: - tokens = fname.split(":") # from https://importlib-resources.readthedocs.io/en/latest/migration.html#pkg-resources-resource-filename # noqa E501 diff --git a/alembic/util/sqla_compat.py b/alembic/util/sqla_compat.py index 376448ac..d356abcd 100644 --- a/alembic/util/sqla_compat.py +++ b/alembic/util/sqla_compat.py @@ -524,7 +524,6 @@ def _get_constraint_final_name( constraint, _alembic_quote=False ) else: - # prior to SQLAlchemy 1.4, work around quoting logic to get at the # final compiled name without quotes. if hasattr(constraint.name, "quote"): diff --git a/tests/test_autogen_diffs.py b/tests/test_autogen_diffs.py index 70ea10a4..ebba04bb 100644 --- a/tests/test_autogen_diffs.py +++ b/tests/test_autogen_diffs.py @@ -238,7 +238,6 @@ class AutogenDefaultSchemaTest(AutogenFixtureTest, TestBase): __backend__ = True def test_uses_explcit_schema_in_default_one(self): - default_schema = self.bind.dialect.default_schema_name m1 = MetaData() @@ -251,7 +250,6 @@ class AutogenDefaultSchemaTest(AutogenFixtureTest, TestBase): eq_(diffs, []) def test_uses_explcit_schema_in_default_two(self): - default_schema = self.bind.dialect.default_schema_name m1 = MetaData() @@ -268,7 +266,6 @@ class AutogenDefaultSchemaTest(AutogenFixtureTest, TestBase): eq_(diffs[0][1].c.keys(), ["y"]) def test_uses_explcit_schema_in_default_three(self): - default_schema = self.bind.dialect.default_schema_name m1 = MetaData() @@ -300,7 +297,6 @@ class AutogenDefaultSchemaIsNoneTest(AutogenFixtureTest, TestBase): eq_(self.bind.dialect.default_schema_name, None) def test_no_default_schema(self): - m1 = MetaData() m2 = MetaData() @@ -854,7 +850,6 @@ class CompareTypeSpecificityTest(TestBase): def test_compare_type( self, impl_fixture, inspected_type, metadata_type, expected ): - is_( impl_fixture.compare_type( Column("x", inspected_type), Column("x", metadata_type) @@ -1440,7 +1435,6 @@ class AutogenKeyTest(AutogenTest, TestBase): symbols = ["someothertable", "sometable"] def test_autogen(self): - uo = ops.UpgradeOps(ops=[]) ctx = self.autogen_context diff --git a/tests/test_autogen_indexes.py b/tests/test_autogen_indexes.py index abefd662..9ec33d0f 100644 --- a/tests/test_autogen_indexes.py +++ b/tests/test_autogen_indexes.py @@ -1446,7 +1446,6 @@ def _lots_of_indexes(flatten: bool = False): req = config.requirements.reflects_indexes_column_sorting if flatten: - flat = list(itertools.chain.from_iterable(diff_pairs)) for f1, f2 in with_sort: flat.extend([(f1, req), (f2, req)]) diff --git a/tests/test_autogen_render.py b/tests/test_autogen_render.py index c4f474e8..7a03cc15 100644 --- a/tests/test_autogen_render.py +++ b/tests/test_autogen_render.py @@ -1621,7 +1621,6 @@ class AutogenRenderTest(TestBase): ) def test_generic_array_type(self): - eq_ignore_whitespace( autogenerate.render._repr_type( types.ARRAY(Integer), self.autogen_context @@ -1757,7 +1756,6 @@ class AutogenRenderTest(TestBase): ) def test_render_variant(self): - self.autogen_context.opts["user_module_prefix"] = None type_ = ( @@ -2213,7 +2211,6 @@ class AutogenRenderTest(TestBase): class RenderNamingConventionTest(TestBase): def setUp(self): - convention = { "ix": "ix_%(custom)s_%(column_0_label)s", "uq": "uq_%(custom)s_%(table_name)s_%(column_0_name)s", diff --git a/tests/test_batch.py b/tests/test_batch.py index 5920cdf8..dd1c0089 100644 --- a/tests/test_batch.py +++ b/tests/test_batch.py @@ -901,7 +901,6 @@ class BatchApplyTest(TestBase): class BatchAPITest(TestBase): @contextmanager def _fixture(self, schema=None): - migration_context = mock.Mock( opts={}, impl=mock.MagicMock(__dialect__="sqlite", connection=object()), diff --git a/tests/test_command.py b/tests/test_command.py index 0937930e..9047f3f7 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -1210,7 +1210,6 @@ class CommandLineTest(TestBase): ) def test_init_w_package(self): - path = os.path.join(_get_staging_directory(), "foobar") with mock.patch("alembic.command.open") as open_: diff --git a/tests/test_external_dialect.py b/tests/test_external_dialect.py index de66517e..8be1a256 100644 --- a/tests/test_external_dialect.py +++ b/tests/test_external_dialect.py @@ -101,7 +101,6 @@ class ExternalDialectRenderTest(TestBase): ) def test_external_nested_render_sqla_type(self): - eq_ignore_whitespace( autogenerate.render._repr_type( EXT_ARRAY(sqla_types.Integer), self.autogen_context @@ -126,7 +125,6 @@ class ExternalDialectRenderTest(TestBase): ) def test_external_nested_render_external_type(self): - eq_ignore_whitespace( autogenerate.render._repr_type( EXT_ARRAY(FOOBARTYPE), self.autogen_context diff --git a/tests/test_offline_environment.py b/tests/test_offline_environment.py index 714d2480..8188d2cf 100644 --- a/tests/test_offline_environment.py +++ b/tests/test_offline_environment.py @@ -264,7 +264,6 @@ assert not context.requires_connection() command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True) def test_running_comments_not_in_sql(self): - message = "this is a very long \nand multiline\nmessage" d = command.revision(self.cfg, message=message) diff --git a/tests/test_op.py b/tests/test_op.py index 6aca753d..54637fd3 100644 --- a/tests/test_op.py +++ b/tests/test_op.py @@ -56,7 +56,6 @@ class OpTest(TestBase): context.assert_("CREATE INDEX name ON tname (foo(x))") def test_add_column_schema_hard_quoting(self): - context = op_fixture("postgresql") op.add_column( "somename", @@ -69,7 +68,6 @@ class OpTest(TestBase): ) def test_rename_table_schema_hard_quoting(self): - context = op_fixture("postgresql") op.rename_table( "t1", "t2", schema=quoted_name("some.schema", quote=True) @@ -78,7 +76,6 @@ class OpTest(TestBase): context.assert_('ALTER TABLE "some.schema".t1 RENAME TO t2') def test_add_constraint_schema_hard_quoting(self): - context = op_fixture("postgresql") op.create_check_constraint( "ck_user_name_len", diff --git a/tests/test_post_write.py b/tests/test_post_write.py index a8bcd2fd..85e95fb9 100644 --- a/tests/test_post_write.py +++ b/tests/test_post_write.py @@ -154,7 +154,6 @@ class RunHookTest(TestBase): ), mock.patch( "alembic.script.write_hooks.subprocess" ) as mock_subprocess: - rev = command.revision(self.cfg, message="x") eq_(importlib_metadata_get.mock_calls, [mock.call("console_scripts")]) @@ -191,7 +190,6 @@ black.options = -l 79 @combinations(True, False) def test_filename_interpolation(self, posix): - input_config = """ [post_write_hooks] hooks = black @@ -223,7 +221,6 @@ black.options = arg1 REVISION_SCRIPT_FILENAME 'multi-word arg' \ ) def test_path_in_config(self): - input_config = """ [post_write_hooks] hooks = black diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index 82a3f3b5..7b7afdc0 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -957,7 +957,6 @@ class PostgresqlAutogenRenderTest(TestBase): ) def test_postgresql_array_type(self): - eq_ignore_whitespace( autogenerate.render._repr_type( ARRAY(Integer), self.autogen_context @@ -1011,7 +1010,6 @@ class PostgresqlAutogenRenderTest(TestBase): ) def test_generic_array_type(self): - eq_ignore_whitespace( autogenerate.render._repr_type( types.ARRAY(Integer), self.autogen_context @@ -1341,7 +1339,6 @@ class PGUniqueIndexAutogenerateTest(AutogenFixtureTest, TestBase): @config.requirements.btree_gist def test_exclude_const_unchanged(self): - m1 = MetaData() m2 = MetaData() diff --git a/tests/test_revision.py b/tests/test_revision.py index 0d5bfd54..1534a681 100644 --- a/tests/test_revision.py +++ b/tests/test_revision.py @@ -649,7 +649,6 @@ class BranchTravellingTest(DownIterateTest): ) def test_three_branches_end_in_single_branch(self): - self._assert_iteration( ["merge", "fe1b1"], "a3", @@ -670,7 +669,6 @@ class BranchTravellingTest(DownIterateTest): ) def test_two_branches_to_root(self): - # here we want 'a3' as a "stop" branch point, but *not* # 'db1', as we don't have multiple traversals on db1 self._assert_iteration( @@ -721,7 +719,6 @@ class BranchTravellingTest(DownIterateTest): ) def test_three_branches_to_root(self): - # in this case, both "a3" and "db1" are stop points self._assert_iteration( ["merge", "fe1b1"], @@ -746,7 +743,6 @@ class BranchTravellingTest(DownIterateTest): ) def test_three_branches_end_multiple_bases(self): - # in this case, both "a3" and "db1" are stop points self._assert_iteration( ["merge", "fe1b1"], @@ -765,7 +761,6 @@ class BranchTravellingTest(DownIterateTest): ) def test_three_branches_end_multiple_bases_exclusive(self): - self._assert_iteration( ["merge", "fe1b1"], ["cb1", "cb2"], diff --git a/tests/test_script_consumption.py b/tests/test_script_consumption.py index a107b805..94c1768e 100644 --- a/tests/test_script_consumption.py +++ b/tests/test_script_consumption.py @@ -813,7 +813,6 @@ class IgnoreFilesTest(TestBase): clear_staging_env() def _test_ignore_file_py(self, fname): - command.revision(self.cfg, message="some rev") script = ScriptDirectory.from_config(self.cfg) path = os.path.join(script.versions, fname) @@ -1076,7 +1075,6 @@ class RecursiveScriptDirectoryTest(TestBase): @testing.fixture def multi_base_fixture(self): - self.env = staging_env() self.cfg = _multi_dir_testing_config() self.cfg.set_main_option("recursive_version_locations", "true") diff --git a/tests/test_sqlite.py b/tests/test_sqlite.py index a580eb20..d3c5367b 100644 --- a/tests/test_sqlite.py +++ b/tests/test_sqlite.py @@ -64,7 +64,6 @@ class SQLiteTest(TestBase): @config.requirements.comments def test_create_table_with_comment_ignored(self): - context = op_fixture("sqlite") op.create_table( "t2", @@ -79,7 +78,6 @@ class SQLiteTest(TestBase): @config.requirements.comments def test_add_column_with_comment_ignored(self): - context = op_fixture("sqlite") op.add_column("t1", Column("c1", Integer, comment="c1 comment")) context.assert_("ALTER TABLE t1 ADD COLUMN c1 INTEGER") diff --git a/tests/test_version_traversal.py b/tests/test_version_traversal.py index f7ad4f08..e1504b9c 100644 --- a/tests/test_version_traversal.py +++ b/tests/test_version_traversal.py @@ -119,7 +119,6 @@ class RevisionPathTest(MigrationTest): ) def test_invalid_relative_upgrade_path(self): - assert_raises_message( util.CommandError, "Relative revision -2 didn't produce 2 migrations", @@ -137,7 +136,6 @@ class RevisionPathTest(MigrationTest): ) def test_downgrade_path(self): - self._assert_downgrade( self.c.revision, self.e.revision, @@ -153,7 +151,6 @@ class RevisionPathTest(MigrationTest): ) def test_relative_downgrade_path(self): - self._assert_downgrade( "-1", self.c.revision, [self.down_(self.c)], {self.b.revision} ) @@ -180,7 +177,6 @@ class RevisionPathTest(MigrationTest): ) def test_invalid_relative_downgrade_path(self): - assert_raises_message( util.CommandError, "Relative revision -5 didn't produce 5 migrations", @@ -198,7 +194,6 @@ class RevisionPathTest(MigrationTest): ) def test_invalid_move_rev_to_none(self): - assert_raises_message( util.CommandError, r"Destination %s is not a valid downgrade " @@ -209,7 +204,6 @@ class RevisionPathTest(MigrationTest): ) def test_invalid_move_higher_to_lower(self): - assert_raises_message( util.CommandError, r"Destination %s is not a valid downgrade " @@ -282,7 +276,6 @@ class BranchedPathTest(MigrationTest): ) def test_upgrade_single_branch(self): - self._assert_upgrade( self.d1.revision, self.b.revision, @@ -321,7 +314,6 @@ class BranchedPathTest(MigrationTest): ) def test_relative_upgrade(self): - self._assert_upgrade( "c2branch@head-1", self.b.revision, @@ -616,7 +608,6 @@ class BranchFromMergepointTest(MigrationTest): ) def test_mergepoint_to_only_one_side_downgrade(self): - self._assert_downgrade( self.b1.revision, (self.d2.revision, self.d1.revision), @@ -691,7 +682,6 @@ class BranchFrom3WayMergepointTest(MigrationTest): clear_staging_env() def test_mergepoint_to_only_one_side_upgrade(self): - self._assert_upgrade( self.d1.revision, (self.d3.revision, self.d2.revision, self.b1.revision), @@ -708,7 +698,6 @@ class BranchFrom3WayMergepointTest(MigrationTest): ) def test_mergepoint_to_two_sides_upgrade(self): - self._assert_upgrade( self.d1.revision, (self.d3.revision, self.b2.revision, self.b1.revision), @@ -1176,7 +1165,6 @@ class DependsOnBranchTestFour(MigrationTest): clear_staging_env() def test_dependencies_are_normalized(self): - heads = [self.b4.revision] self._assert_downgrade( @@ -1378,7 +1366,6 @@ class MergedPathTest(MigrationTest): ) def test_upgrade_across_merge_point(self): - eq_( self.env._upgrade_revs(self.f.revision, self.b.revision), [ @@ -1393,7 +1380,6 @@ class MergedPathTest(MigrationTest): ) def test_downgrade_across_merge_point(self): - eq_( self.env._downgrade_revs(self.b.revision, self.f.revision), [ diff --git a/tools/write_pyi.py b/tools/write_pyi.py index da5b4845..499d830f 100644 --- a/tools/write_pyi.py +++ b/tools/write_pyi.py @@ -41,7 +41,7 @@ TRIM_MODULE = [ "sqlalchemy.sql.type_api.", "sqlalchemy.sql.functions.", "sqlalchemy.sql.dml.", - "typing." + "typing.", ] ADDITIONAL_ENV = { "MigrationContext": MigrationContext, diff --git a/tox.ini b/tox.ini index 8a317acf..62ef921a 100644 --- a/tox.ini +++ b/tox.ini @@ -96,7 +96,7 @@ deps= pydocstyle<4.0.0 # used by flake8-rst-docstrings pygments - black==22.3.0 + black==23.3.0 commands = flake8 ./alembic/ ./tests/ setup.py docs/build/conf.py {posargs} black --check setup.py tests alembic