From: TilmanK Date: Tue, 14 Sep 2021 19:39:59 +0000 (-0400) Subject: Fix constraint_name type of create_foreign_key X-Git-Tag: rel_1_7_3~1^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4abcbcd56ae1a657334195a18c46bd6b3d5e444a;p=thirdparty%2Fsqlalchemy%2Falembic.git Fix constraint_name type of create_foreign_key Fixed type annotations for the "constraint_name" argument of operations ``create_primary_key()``, ``create_foreign_key()``. Pull request courtesy TilmanK. Closes: #914 Pull-request: https://github.com/sqlalchemy/alembic/pull/914 Pull-request-sha: 39d44af226b2103da3964daf3229880a0958b97c Change-Id: Iec4b392c70ae0eeda06dcbfda95a2f044e976686 --- diff --git a/alembic/op.pyi b/alembic/op.pyi index f5aca925..2a03e1e2 100644 --- a/alembic/op.pyi +++ b/alembic/op.pyi @@ -508,7 +508,7 @@ def create_exclude_constraint( """ def create_foreign_key( - constraint_name: str, + constraint_name: Optional[str], source_table: str, referent_table: str, local_cols: List[str], @@ -541,9 +541,9 @@ def create_foreign_key( off normally. The :class:`~sqlalchemy.schema.AddConstraint` construct is ultimately used to generate the ALTER statement. - :param name: Name of the foreign key constraint. The name is necessary - so that an ALTER statement can be emitted. For setups that - use an automated naming scheme such as that described at + :param constraint_name: Name of the foreign key constraint. The name + is necessary so that an ALTER statement can be emitted. For setups + that use an automated naming scheme such as that described at :ref:`sqla:constraint_naming_conventions`, ``name`` here can be ``None``, as the event listener will apply the name to the constraint object when it is associated @@ -618,7 +618,7 @@ def create_index( """ def create_primary_key( - constraint_name: str, + constraint_name: Optional[str], table_name: str, columns: List[str], schema: Optional[str] = None, @@ -643,9 +643,9 @@ def create_primary_key( off normally. The :class:`~sqlalchemy.schema.AddConstraint` construct is ultimately used to generate the ALTER statement. - :param name: Name of the primary key constraint. The name is necessary - so that an ALTER statement can be emitted. For setups that - use an automated naming scheme such as that described at + :param constraint_name: Name of the primary key constraint. The name + is necessary so that an ALTER statement can be emitted. For setups + that use an automated naming scheme such as that described at :ref:`sqla:constraint_naming_conventions` ``name`` here can be ``None``, as the event listener will apply the name to the constraint object when it is associated @@ -1002,7 +1002,7 @@ def execute( op.execute("INSERT INTO table (foo) VALUES ('\:colon_value')") - :param sql: Any legal SQLAlchemy expression, including: + :param sqltext: Any legal SQLAlchemy expression, including: * a string * a :func:`sqlalchemy.sql.expression.text` construct. diff --git a/alembic/operations/ops.py b/alembic/operations/ops.py index d5ddbc94..7d69f093 100644 --- a/alembic/operations/ops.py +++ b/alembic/operations/ops.py @@ -296,7 +296,7 @@ class CreatePrimaryKeyOp(AddConstraintOp): def create_primary_key( cls, operations: "Operations", - constraint_name: str, + constraint_name: Optional[str], table_name: str, columns: List[str], schema: Optional[str] = None, @@ -321,9 +321,9 @@ class CreatePrimaryKeyOp(AddConstraintOp): off normally. The :class:`~sqlalchemy.schema.AddConstraint` construct is ultimately used to generate the ALTER statement. - :param name: Name of the primary key constraint. The name is necessary - so that an ALTER statement can be emitted. For setups that - use an automated naming scheme such as that described at + :param constraint_name: Name of the primary key constraint. The name + is necessary so that an ALTER statement can be emitted. For setups + that use an automated naming scheme such as that described at :ref:`sqla:constraint_naming_conventions` ``name`` here can be ``None``, as the event listener will apply the name to the constraint object when it is associated @@ -588,7 +588,7 @@ class CreateForeignKeyOp(AddConstraintOp): def create_foreign_key( cls, operations: "Operations", - constraint_name: str, + constraint_name: Optional[str], source_table: str, referent_table: str, local_cols: List[str], @@ -621,9 +621,9 @@ class CreateForeignKeyOp(AddConstraintOp): off normally. The :class:`~sqlalchemy.schema.AddConstraint` construct is ultimately used to generate the ALTER statement. - :param name: Name of the foreign key constraint. The name is necessary - so that an ALTER statement can be emitted. For setups that - use an automated naming scheme such as that described at + :param constraint_name: Name of the foreign key constraint. The name + is necessary so that an ALTER statement can be emitted. For setups + that use an automated naming scheme such as that described at :ref:`sqla:constraint_naming_conventions`, ``name`` here can be ``None``, as the event listener will apply the name to the constraint object when it is associated @@ -2389,7 +2389,7 @@ class ExecuteSQLOp(MigrateOperation): op.execute("INSERT INTO table (foo) VALUES ('\:colon_value')") - :param sql: Any legal SQLAlchemy expression, including: + :param sqltext: Any legal SQLAlchemy expression, including: * a string * a :func:`sqlalchemy.sql.expression.text` construct. diff --git a/docs/build/unreleased/914.rst b/docs/build/unreleased/914.rst new file mode 100644 index 00000000..cbc9f34d --- /dev/null +++ b/docs/build/unreleased/914.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: bug, mypy + :tickets: 914 + + Fixed type annotations for the "constraint_name" argument of operations + ``create_primary_key()``, ``create_foreign_key()``. Pull request courtesy + TilmanK. +