41
41
from .base import NO_ARG
42
42
from .base import SchemaEventTarget
43
43
from .cache_key import HasCacheKey
44
- from .elements import BinaryExpression
45
44
from .elements import quoted_name
46
45
from .elements import Slice
47
46
from .elements import TypeCoerce as type_coerce # noqa
48
- from .type_api import _LiteralProcessorType
49
47
from .type_api import Emulated
48
+ from .type_api import NativeForEmulated # noqa
50
49
from .type_api import to_instance as to_instance
51
50
from .type_api import TypeDecorator as TypeDecorator
52
51
from .type_api import TypeEngine as TypeEngine
53
52
from .type_api import TypeEngineMixin
53
+ from .type_api import Variant # noqa
54
54
from .visitors import InternalTraversal
55
- from .. import Compiled
56
55
from .. import event
57
56
from .. import exc
58
57
from .. import inspection
67
66
68
67
from ._typing import _ColumnExpressionArgument
69
68
from ._typing import _TypeEngineArgument
69
+ from .elements import BinaryExpression
70
70
from .elements import ColumnElement
71
71
from .operators import OperatorType
72
72
from .schema import Column
73
73
from .schema import MetaData
74
74
from .schema import Table
75
75
from .type_api import _BindProcessorType
76
76
from .type_api import _ComparatorFactory
77
+ from .type_api import _LiteralProcessorType
77
78
from .type_api import _MatchedOnType
78
79
from .type_api import _ResultProcessorType
80
+ from .. import Compiled
79
81
from ..engine .interfaces import Connectable
80
82
from ..engine .interfaces import Dialect
81
83
@@ -564,7 +566,9 @@ def bind_processor(
564
566
else :
565
567
return processors .to_float # type: ignore
566
568
567
- def result_processor (self , dialect : Dialect , coltype : _T ) -> Optional [_ResultProcessorType [_N ]]: # type: ignore
569
+ def result_processor (
570
+ self , dialect : Dialect , coltype : _T
571
+ ) -> Optional [_ResultProcessorType [_N ]]: # type: ignore
568
572
if self .asdecimal :
569
573
if dialect .supports_native_decimal :
570
574
# we're a "numeric", DBAPI will give us Decimal directly
@@ -740,14 +744,16 @@ def _literal_processor_portion(
740
744
741
745
def process (value : Optional [dt .datetime ]) -> Optional [str ]:
742
746
if value is not None :
743
- value = f"""'{ value .isoformat ().split ("T" )[_portion ]} '""" # type: ignore
747
+ value = f"""'{ value .isoformat ()
748
+ .split ("T" )[_portion ]} '""" # type: ignore
744
749
return value # type: ignore
745
750
746
751
else :
747
752
748
753
def process (value : Optional [dt .datetime ]) -> Optional [str ]:
749
754
if value is not None :
750
- value = f"""'{ value .isoformat ().replace ("T" , " " )} '""" # type: ignore
755
+ value = f"""'{ value .isoformat ()
756
+ .replace ("T" , " " )} '""" # type: ignore
751
757
return value # type: ignore
752
758
753
759
return process # type: ignore
@@ -1048,18 +1054,24 @@ def __init__(
1048
1054
event .listen (
1049
1055
self .metadata ,
1050
1056
"before_create" ,
1051
- util .portable_instancemethod (self ._on_metadata_create ), # type: ignore
1057
+ util .portable_instancemethod (
1058
+ self ._on_metadata_create
1059
+ ), # type: ignore
1052
1060
)
1053
1061
event .listen (
1054
1062
self .metadata ,
1055
1063
"after_drop" ,
1056
- util .portable_instancemethod (self ._on_metadata_drop ), # type: ignore
1064
+ util .portable_instancemethod (
1065
+ self ._on_metadata_drop
1066
+ ), # type: ignore
1057
1067
)
1058
1068
1059
1069
if _adapted_from :
1060
1070
self .dispatch = self .dispatch ._join (_adapted_from .dispatch )
1061
1071
1062
- def _set_parent (self , column : Column [_T ], ** kw : _T ) -> None : # type: ignore
1072
+ def _set_parent ( # type: ignore
1073
+ self , column : Column [_T ], ** kw : _T
1074
+ ) -> None :
1063
1075
# set parent hook is when this type is associated with a column.
1064
1076
# Column calls it for all SchemaEventTarget instances, either the
1065
1077
# base type and/or variants in _variant_mapping.
@@ -1073,7 +1085,9 @@ def _set_parent(self, column: Column[_T], **kw: _T) -> None: # type: ignore
1073
1085
# on_table/metadata_create/drop in this method, which is used by
1074
1086
# "native" types with a separate CREATE/DROP e.g. Postgresql.ENUM
1075
1087
1076
- column ._on_table_attach (util .portable_instancemethod (self ._set_table )) # type: ignore
1088
+ column ._on_table_attach (
1089
+ util .portable_instancemethod (self ._set_table ) # type: ignore
1090
+ )
1077
1091
1078
1092
def _variant_mapping_for_set_table (
1079
1093
self , column : Column [_T ]
@@ -1131,7 +1145,7 @@ def _set_table(self, column: Column[_T], table: Table) -> None:
1131
1145
),
1132
1146
)
1133
1147
1134
- def copy (self , ** kw : _T ) -> TypeEngine [_T ]:
1148
+ def copy (self , ** kw : _T ) -> TypeEngine [Any ]:
1135
1149
return self .adapt (
1136
1150
cast ("Type[TypeEngine[Any]]" , self .__class__ ),
1137
1151
_create_events = True ,
@@ -1146,7 +1160,7 @@ def adapt(self, cls: Type[TypeEngineMixin], **kw: Any) -> TypeEngine[Any]:
1146
1160
...
1147
1161
1148
1162
def adapt (
1149
- self , cls : Type [Union [TypeEngine [ Any ] , TypeEngineMixin ]], ** kw : Any
1163
+ self , cls : Type [Union [_TE , TypeEngineMixin ]], ** kw : Any
1150
1164
) -> TypeEngine [Any ]:
1151
1165
kw .setdefault ("_create_events" , False )
1152
1166
kw .setdefault ("_adapted_from" , self )
@@ -1206,7 +1220,9 @@ def _on_metadata_drop(
1206
1220
if isinstance (t , SchemaType ) and t .__class__ is not self .__class__ :
1207
1221
t ._on_metadata_drop (target , bind , ** kw )
1208
1222
1209
- def _is_impl_for_variant (self , dialect : Dialect , kw : _T ) -> bool : # type: ignore
1223
+ def _is_impl_for_variant ( # type: ignore
1224
+ self , dialect : Dialect , kw : _T
1225
+ ) -> bool :
1210
1226
variant_mapping = kw .pop ("variant_mapping" , None )
1211
1227
1212
1228
if not variant_mapping :
@@ -1521,11 +1537,15 @@ def _parse_into_values(
1521
1537
if len (enums ) == 1 and hasattr (enums [0 ], "__members__" ):
1522
1538
self .enum_class : Optional [enum .EnumMeta ] = enums [0 ]
1523
1539
1524
- _members : Dict [str , _T ] = self .enum_class .__members__ # type: ignore
1540
+ _members : Dict [
1541
+ str , Any
1542
+ ] = self .enum_class .__members__ # type: ignore
1525
1543
if self ._omit_aliases is True :
1526
1544
# remove aliases
1527
1545
members = OrderedDict (
1528
- (n , v ) for n , v in _members .items () if v .name == n # type: ignore
1546
+ (n , v )
1547
+ for n , v in _members .items ()
1548
+ if v .name == n # type: ignore
1529
1549
)
1530
1550
else :
1531
1551
members = _members
@@ -1611,7 +1631,9 @@ def _db_value_for_elem(self, elem: Any) -> Any:
1611
1631
% (
1612
1632
elem ,
1613
1633
self .name ,
1614
- langhelpers .repr_tuple_names (self .enums ), # type: ignore
1634
+ langhelpers .repr_tuple_names (
1635
+ self .enums # type: ignore
1636
+ ),
1615
1637
)
1616
1638
) from err
1617
1639
@@ -1671,7 +1693,9 @@ def as_generic(self, allow_nulltype: bool = False) -> TypeEngine[Any]:
1671
1693
self , self ._generic_type_affinity , * args , _disable_warnings = True
1672
1694
)
1673
1695
1674
- def adapt_to_emulated (self , impltype : Type [TypeEngine [Any ]], ** kw : Any ) -> TypeEngine [Any ]: # type: ignore
1696
+ def adapt_to_emulated ( # type: ignore
1697
+ self , impltype : Type [_TE ], ** kw : Any
1698
+ ) -> _TE :
1675
1699
kw .setdefault ("validate_strings" , self .validate_strings )
1676
1700
kw .setdefault ("name" , self .name )
1677
1701
kw ["_disable_warnings" ] = True
@@ -1687,7 +1711,9 @@ def adapt_to_emulated(self, impltype: Type[TypeEngine[Any]], **kw: Any) -> TypeE
1687
1711
assert "_enums" in kw
1688
1712
return impltype (** kw )
1689
1713
1690
- def adapt (self , impltype : Type [TypeEngine [Any ]], ** kw : Any ) -> TypeEngine [Any ]: # type: ignore
1714
+ def adapt ( # type: ignore
1715
+ self , impltype : Type [_TE ], ** kw : Any
1716
+ ) -> TypeEngine [Any ]:
1691
1717
kw ["_enums" ] = self ._enums_argument
1692
1718
kw ["_disable_warnings" ] = True
1693
1719
return super ().adapt (impltype , ** kw )
@@ -1733,7 +1759,9 @@ def process(value: Any) -> Any:
1733
1759
1734
1760
return process
1735
1761
1736
- def bind_processor (self , dialect : Dialect ) -> Optional [_BindProcessorType [_T ]]: # type: ignore
1762
+ def bind_processor ( # type: ignore
1763
+ self , dialect : Dialect
1764
+ ) -> Optional [_BindProcessorType [_T ]]:
1737
1765
parent_processor = super ().bind_processor (dialect )
1738
1766
1739
1767
def process (value : Any ) -> Any :
@@ -1744,7 +1772,9 @@ def process(value: Any) -> Any:
1744
1772
1745
1773
return process
1746
1774
1747
- def result_processor (self , dialect : Dialect , coltype : _T ) -> Optional [_ResultProcessorType [_T ]]: # type: ignore
1775
+ def result_processor ( # type: ignore
1776
+ self , dialect : Dialect , coltype : _T
1777
+ ) -> Optional [_ResultProcessorType [_T ]]:
1748
1778
parent_processor = super ().result_processor (dialect , coltype )
1749
1779
1750
1780
def process (value : _T ) -> _T :
@@ -1942,7 +1972,7 @@ def _should_create_constraint(self, compiler: Compiled, **kw: Any) -> bool:
1942
1972
return False
1943
1973
return (
1944
1974
not compiler .dialect .supports_native_boolean
1945
- and compiler .dialect .non_native_boolean_check_constraint # type: ignore
1975
+ and compiler .dialect .non_native_boolean_check_constraint # type: ignore # noqa
1946
1976
)
1947
1977
1948
1978
@util .preload_module ("sqlalchemy.sql.schema" )
@@ -2544,7 +2574,9 @@ class Comparator(Indexable.Comparator[_T], Concatenable.Comparator[_T]):
2544
2574
2545
2575
__slots__ = ()
2546
2576
2547
- def _setup_getitem (self , index : Any ) -> Tuple [OperatorType , Any , TypeEngine [_T ]]: # type: ignore
2577
+ def _setup_getitem ( # type: ignore
2578
+ self , index : Any
2579
+ ) -> Tuple [OperatorType , Any , TypeEngine [_T ]]:
2548
2580
if not isinstance (index , str ) and isinstance (
2549
2581
index , collections_abc .Sequence
2550
2582
):
@@ -2742,15 +2774,21 @@ def process(value: Any) -> Any:
2742
2774
2743
2775
def bind_processor (self , dialect : Dialect ) -> Callable [[Any ], Any ]:
2744
2776
string_process = self ._str_impl .bind_processor (dialect ) # type: ignore
2745
- json_serializer = dialect ._json_serializer or json .dumps # type: ignore
2777
+ json_serializer = (
2778
+ dialect ._json_serializer or json .dumps # type: ignore
2779
+ )
2746
2780
2747
2781
return self ._make_bind_processor (string_process , json_serializer )
2748
2782
2749
2783
def result_processor (
2750
2784
self , dialect : Dialect , coltype : _T
2751
2785
) -> Callable [[Any ], Any ]:
2752
- string_process = self ._str_impl .result_processor (dialect , coltype ) # type: ignore
2753
- json_deserializer = dialect ._json_deserializer or json .loads # type: ignore
2786
+ string_process = self ._str_impl .result_processor (
2787
+ dialect , coltype
2788
+ ) # type: ignore
2789
+ json_deserializer = (
2790
+ dialect ._json_deserializer or json .loads # type: ignore
2791
+ )
2754
2792
2755
2793
def process (value : _T ) -> Any :
2756
2794
if value is None :
@@ -3116,13 +3154,17 @@ def python_type(self) -> Type[List[Any]]:
3116
3154
def compare_values (self , x : _T , y : _T ) -> Any :
3117
3155
return x == y
3118
3156
3119
- def _set_parent (self , column : Column , outer : bool = False , ** kw : _T ) -> None : # type: ignore
3157
+ def _set_parent ( # type: ignore
3158
+ self , column : Column [_T ], outer : bool = False , ** kw : _T
3159
+ ) -> None :
3120
3160
"""Support SchemaEventTarget"""
3121
3161
3122
3162
if not outer and isinstance (self .item_type , SchemaEventTarget ):
3123
3163
self .item_type ._set_parent (column , ** kw )
3124
3164
3125
- def _set_parent_with_dispatch (self , parent : SchemaEventTarget ) -> None : # type: ignore
3165
+ def _set_parent_with_dispatch ( # type: ignore
3166
+ self , parent : SchemaEventTarget
3167
+ ) -> None :
3126
3168
"""Support SchemaEventTarget"""
3127
3169
3128
3170
super ()._set_parent_with_dispatch (parent , outer = True )
@@ -3204,7 +3246,7 @@ class TupleType(TypeEngine[Tuple[Any, ...]]):
3204
3246
3205
3247
_is_tuple_type = True
3206
3248
3207
- types : List [TypeEngine [Any ]]
3249
+ types : Sequence [TypeEngine [Any ]]
3208
3250
3209
3251
def __init__ (self , * types : _TypeEngineArgument [Any ]):
3210
3252
self ._fully_typed = NULLTYPE not in types
0 commit comments