]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
update for mypy 1.0 dev
authorFederico Caselli <cfederico87@gmail.com>
Sun, 27 Nov 2022 17:11:34 +0000 (18:11 +0100)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 29 Nov 2022 19:15:16 +0000 (14:15 -0500)
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

lib/sqlalchemy/orm/instrumentation.py
lib/sqlalchemy/orm/util.py
lib/sqlalchemy/sql/base.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/elements.py
lib/sqlalchemy/sql/expression.py
lib/sqlalchemy/sql/naming.py
lib/sqlalchemy/sql/schema.py
lib/sqlalchemy/sql/sqltypes.py
test/sql/test_metadata.py

index dfe09fcbd39211e544e1e0b10484bf1365bb1d06..85fd957929951abd9c90e7ad571f4a10615fc3fc 100644 (file)
@@ -621,7 +621,7 @@ class InstrumentationFactory(EventTarget):
 
         if factory is None:
             factory = ClassManager
-            manager = factory(class_)
+            manager = ClassManager(class_)
         else:
             assert manager is not None
 
index 58407a74d41fb2f986f7c6bc9630969ddb259492..c0fc11d2330f5617ac998dfa441eb3446336c8c1 100644 (file)
@@ -1365,7 +1365,7 @@ def _inspect_mc(
         return mapper
 
 
-GenericAlias = type(List[_T])
+GenericAlias = type(List[Any])
 
 
 @inspection._inspects(GenericAlias)
index c81891169640f953568772c0416c1a3822b9bdea..fc80334e874582606c7d1627657e02663d0bc41e 100644 (file)
@@ -103,6 +103,14 @@ class _NoArg(Enum):
 
 NO_ARG = _NoArg.NO_ARG
 
+
+class _NoneName(Enum):
+    NONE_NAME = 0
+    """indicate a 'deferred' name that was ultimately the value None."""
+
+
+_NONE_NAME = _NoneName.NONE_NAME
+
 _T = TypeVar("_T", bound=Any)
 
 _Fn = TypeVar("_Fn", bound=Callable[..., Any])
index 9e4422fbd07e61235dceed7e422ceee7912a2b54..50cf9b477ca25f77e5ad712cc84591ecd9c9c6e2 100644 (file)
@@ -67,6 +67,7 @@ from . import util as sql_util
 from ._typing import is_column_element
 from ._typing import is_dml
 from .base import _from_objects
+from .base import _NONE_NAME
 from .base import Executable
 from .base import NO_ARG
 from .elements import ClauseElement
@@ -6440,7 +6441,7 @@ class IdentifierPreparer:
     def format_constraint(self, constraint, _alembic_quote=True):
         naming = util.preloaded.sql_naming
 
-        if constraint.name is elements._NONE_NAME:
+        if constraint.name is _NONE_NAME:
             name = naming._constraint_name_for_table(
                 constraint, constraint.table
             )
index 6a9bd74caaafd397c8e892e4b8dba844a1790911..eff8c9bc11ba62f19cb254eac3afc46e97afb32c 100644 (file)
@@ -5112,9 +5112,6 @@ class conv(_truncated_label):
     __slots__ = ()
 
 
-_NONE_NAME = util.symbol("NONE_NAME")
-"""indicate a 'deferred' name that was ultimately the value None."""
-
 # for backwards compatibility in case
 # someone is re-implementing the
 # _truncated_identifier() sequence in a custom
index 2498bfb377353b7800f993f1d9c51819a8905062..a3fed1d568cf162a7cd7db082c8c8e8a174e654e 100644 (file)
@@ -136,6 +136,7 @@ from .selectable import (
 from .selectable import Lateral as Lateral
 from .selectable import ReturnsRows as ReturnsRows
 from .selectable import ScalarSelect as ScalarSelect
+from .selectable import ScalarValues as ScalarValues
 from .selectable import Select as Select
 from .selectable import Selectable as Selectable
 from .selectable import SelectBase as SelectBase
index eaa5d8dd3b7a768820b3508659f406162702d9c2..0fe1490018d9648a874d488a8544c2f13df7b8e3 100644 (file)
@@ -16,7 +16,7 @@ from __future__ import annotations
 import re
 
 from . import events  # noqa
-from .elements import _NONE_NAME
+from .base import _NONE_NAME
 from .elements import conv as conv
 from .schema import CheckConstraint
 from .schema import Column
index f1caf79be8335d39f3585d558d1c46e96bcebb96..2d04b28a8710e5621d5d6290b45aef1ab2d5c5b7 100644 (file)
@@ -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,
index 624b7d16efc735e11e48408c3f17e3c6c8386c9f..a0f56d8391a32e378c8f77658ccb0e89dcbc31d4 100644 (file)
@@ -37,10 +37,10 @@ from . import elements
 from . import operators
 from . import roles
 from . import type_api
+from .base import _NONE_NAME
 from .base import NO_ARG
 from .base import SchemaEventTarget
 from .cache_key import HasCacheKey
-from .elements import _NONE_NAME
 from .elements import quoted_name
 from .elements import Slice
 from .elements import TypeCoerce as type_coerce  # noqa
index af8c15f98fe4596a8e09e8f13f47612c0ba93690..e50aa236a9487410c3dd6ee881b67723b6bbc7ea 100644 (file)
@@ -44,7 +44,7 @@ from sqlalchemy.schema import DefaultClause
 from sqlalchemy.schema import DropIndex
 from sqlalchemy.sql import naming
 from sqlalchemy.sql import operators
-from sqlalchemy.sql.elements import _NONE_NAME
+from sqlalchemy.sql.base import _NONE_NAME
 from sqlalchemy.sql.elements import literal_column
 from sqlalchemy.sql.schema import RETAIN_SCHEMA
 from sqlalchemy.testing import assert_raises