diff options
author | Federico Caselli <cfederico87@gmail.com> | 2022-11-27 18:11:34 +0100 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-11-29 14:15:16 -0500 |
commit | 78833af4e650d37e6257cfbb541e4db56e2a285f (patch) | |
tree | 0b7f243111b6b072da6230c11f3618758e86ebfa /lib/sqlalchemy/sql/schema.py | |
parent | 07d40578b1bb77456b7a7af425a905b146fdaef1 (diff) | |
download | sqlalchemy-78833af4e650d37e6257cfbb541e4db56e2a285f.tar.gz |
update for mypy 1.0 dev
As I need dmypy to work without facing [1], I am
running the latest build of mypy which seems so far
to finally not have that issue.
update constructs that latest mypy is being more picky
about, including better typing for the _NONE_NAME
symbol used in constraints (porting those elements
from the Enum patch at
I15ac3daee770408b5795746f47c1bbd931b7d26d)
[1] https://github.com/python/mypy/issues/12744
Change-Id: Ib3f56787fa65ea9bb2e6a0bccc4d99f54c516dad
Diffstat (limited to 'lib/sqlalchemy/sql/schema.py')
-rw-r--r-- | lib/sqlalchemy/sql/schema.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index f1caf79be..2d04b28a8 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -58,6 +58,7 @@ from . import ddl from . import roles from . import type_api from . import visitors +from .base import _NoneName from .base import DedupeColumnCollection from .base import DialectKWArgs from .base import Executable @@ -111,6 +112,8 @@ _TAB = TypeVar("_TAB", bound="Table") _CreateDropBind = Union["Engine", "Connection", "MockConnection"] +_ConstraintNameArgument = Optional[Union[str, _NoneName]] + class SchemaConst(Enum): @@ -1927,11 +1930,7 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause[_T]): self._proxies = _proxies else: # otherwise, add DDL-related events - if isinstance(self.type, SchemaEventTarget): - self.type._set_parent_with_dispatch(self) - for impl in self.type._variant_mapping.values(): - if isinstance(impl, SchemaEventTarget): - impl._set_parent_with_dispatch(self) + self._set_type(self.type) if default is not None: if not isinstance(default, (ColumnDefault, Sequence)): @@ -2023,6 +2022,14 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause[_T]): identity: Optional[Identity] + def _set_type(self, type_: TypeEngine[Any]) -> None: + self.type = type_ + if isinstance(self.type, SchemaEventTarget): + self.type._set_parent_with_dispatch(self) + for impl in self.type._variant_mapping.values(): + if isinstance(impl, SchemaEventTarget): + impl._set_parent_with_dispatch(self) + @util.memoized_property def _gen_static_annotations_cache_key(self) -> bool: # type: ignore """special attribute used by cache key gen, if true, we will @@ -2480,7 +2487,7 @@ class ForeignKey(DialectKWArgs, SchemaItem): column: _DDLColumnArgument, _constraint: Optional[ForeignKeyConstraint] = None, use_alter: bool = False, - name: Optional[str] = None, + name: _ConstraintNameArgument = None, onupdate: Optional[str] = None, ondelete: Optional[str] = None, deferrable: Optional[bool] = None, @@ -3744,7 +3751,7 @@ class Constraint(DialectKWArgs, HasConditionalDDL, SchemaItem): def __init__( self, - name: Optional[str] = None, + name: _ConstraintNameArgument = None, deferrable: Optional[bool] = None, initially: Optional[str] = None, info: Optional[_InfoType] = None, @@ -3987,7 +3994,7 @@ class ColumnCollectionConstraint(ColumnCollectionMixin, Constraint): def __init__( self, *columns: _DDLColumnArgument, - name: Optional[str] = None, + name: _ConstraintNameArgument = None, deferrable: Optional[bool] = None, initially: Optional[str] = None, info: Optional[_InfoType] = None, @@ -4123,7 +4130,7 @@ class CheckConstraint(ColumnCollectionConstraint): def __init__( self, sqltext: _TextCoercedExpressionArgument[Any], - name: Optional[str] = None, + name: _ConstraintNameArgument = None, deferrable: Optional[bool] = None, initially: Optional[str] = None, table: Optional[Table] = None, @@ -4238,7 +4245,7 @@ class ForeignKeyConstraint(ColumnCollectionConstraint): self, columns: _typing_Sequence[_DDLColumnArgument], refcolumns: _typing_Sequence[_DDLColumnArgument], - name: Optional[str] = None, + name: _ConstraintNameArgument = None, onupdate: Optional[str] = None, ondelete: Optional[str] = None, deferrable: Optional[bool] = None, |