Skip to content

Commit d270a32

Browse files
author
Maksim Latysh
committed
Fixed imports and beautifying
1 parent 0283b38 commit d270a32

File tree

1 file changed

+70
-28
lines changed

1 file changed

+70
-28
lines changed

lib/sqlalchemy/sql/sqltypes.py

Lines changed: 70 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,17 @@
4141
from .base import NO_ARG
4242
from .base import SchemaEventTarget
4343
from .cache_key import HasCacheKey
44-
from .elements import BinaryExpression
4544
from .elements import quoted_name
4645
from .elements import Slice
4746
from .elements import TypeCoerce as type_coerce # noqa
48-
from .type_api import _LiteralProcessorType
4947
from .type_api import Emulated
48+
from .type_api import NativeForEmulated # noqa
5049
from .type_api import to_instance as to_instance
5150
from .type_api import TypeDecorator as TypeDecorator
5251
from .type_api import TypeEngine as TypeEngine
5352
from .type_api import TypeEngineMixin
53+
from .type_api import Variant # noqa
5454
from .visitors import InternalTraversal
55-
from .. import Compiled
5655
from .. import event
5756
from .. import exc
5857
from .. import inspection
@@ -67,15 +66,18 @@
6766

6867
from ._typing import _ColumnExpressionArgument
6968
from ._typing import _TypeEngineArgument
69+
from .elements import BinaryExpression
7070
from .elements import ColumnElement
7171
from .operators import OperatorType
7272
from .schema import Column
7373
from .schema import MetaData
7474
from .schema import Table
7575
from .type_api import _BindProcessorType
7676
from .type_api import _ComparatorFactory
77+
from .type_api import _LiteralProcessorType
7778
from .type_api import _MatchedOnType
7879
from .type_api import _ResultProcessorType
80+
from .. import Compiled
7981
from ..engine.interfaces import Connectable
8082
from ..engine.interfaces import Dialect
8183

@@ -564,7 +566,9 @@ def bind_processor(
564566
else:
565567
return processors.to_float # type: ignore
566568

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
568572
if self.asdecimal:
569573
if dialect.supports_native_decimal:
570574
# we're a "numeric", DBAPI will give us Decimal directly
@@ -740,14 +744,16 @@ def _literal_processor_portion(
740744

741745
def process(value: Optional[dt.datetime]) -> Optional[str]:
742746
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
744749
return value # type: ignore
745750

746751
else:
747752

748753
def process(value: Optional[dt.datetime]) -> Optional[str]:
749754
if value is not None:
750-
value = f"""'{value.isoformat().replace("T", " ")}'""" # type: ignore
755+
value = f"""'{value.isoformat()
756+
.replace("T", " ")}'""" # type: ignore
751757
return value # type: ignore
752758

753759
return process # type: ignore
@@ -1048,18 +1054,24 @@ def __init__(
10481054
event.listen(
10491055
self.metadata,
10501056
"before_create",
1051-
util.portable_instancemethod(self._on_metadata_create), # type: ignore
1057+
util.portable_instancemethod(
1058+
self._on_metadata_create
1059+
), # type: ignore
10521060
)
10531061
event.listen(
10541062
self.metadata,
10551063
"after_drop",
1056-
util.portable_instancemethod(self._on_metadata_drop), # type: ignore
1064+
util.portable_instancemethod(
1065+
self._on_metadata_drop
1066+
), # type: ignore
10571067
)
10581068

10591069
if _adapted_from:
10601070
self.dispatch = self.dispatch._join(_adapted_from.dispatch)
10611071

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:
10631075
# set parent hook is when this type is associated with a column.
10641076
# Column calls it for all SchemaEventTarget instances, either the
10651077
# base type and/or variants in _variant_mapping.
@@ -1073,7 +1085,9 @@ def _set_parent(self, column: Column[_T], **kw: _T) -> None: # type: ignore
10731085
# on_table/metadata_create/drop in this method, which is used by
10741086
# "native" types with a separate CREATE/DROP e.g. Postgresql.ENUM
10751087

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+
)
10771091

10781092
def _variant_mapping_for_set_table(
10791093
self, column: Column[_T]
@@ -1131,7 +1145,7 @@ def _set_table(self, column: Column[_T], table: Table) -> None:
11311145
),
11321146
)
11331147

1134-
def copy(self, **kw: _T) -> TypeEngine[_T]:
1148+
def copy(self, **kw: _T) -> TypeEngine[Any]:
11351149
return self.adapt(
11361150
cast("Type[TypeEngine[Any]]", self.__class__),
11371151
_create_events=True,
@@ -1146,7 +1160,7 @@ def adapt(self, cls: Type[TypeEngineMixin], **kw: Any) -> TypeEngine[Any]:
11461160
...
11471161

11481162
def adapt(
1149-
self, cls: Type[Union[TypeEngine[Any], TypeEngineMixin]], **kw: Any
1163+
self, cls: Type[Union[_TE, TypeEngineMixin]], **kw: Any
11501164
) -> TypeEngine[Any]:
11511165
kw.setdefault("_create_events", False)
11521166
kw.setdefault("_adapted_from", self)
@@ -1206,7 +1220,9 @@ def _on_metadata_drop(
12061220
if isinstance(t, SchemaType) and t.__class__ is not self.__class__:
12071221
t._on_metadata_drop(target, bind, **kw)
12081222

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:
12101226
variant_mapping = kw.pop("variant_mapping", None)
12111227

12121228
if not variant_mapping:
@@ -1521,11 +1537,15 @@ def _parse_into_values(
15211537
if len(enums) == 1 and hasattr(enums[0], "__members__"):
15221538
self.enum_class: Optional[enum.EnumMeta] = enums[0]
15231539

1524-
_members: Dict[str, _T] = self.enum_class.__members__ # type: ignore
1540+
_members: Dict[
1541+
str, Any
1542+
] = self.enum_class.__members__ # type: ignore
15251543
if self._omit_aliases is True:
15261544
# remove aliases
15271545
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
15291549
)
15301550
else:
15311551
members = _members
@@ -1611,7 +1631,9 @@ def _db_value_for_elem(self, elem: Any) -> Any:
16111631
% (
16121632
elem,
16131633
self.name,
1614-
langhelpers.repr_tuple_names(self.enums), # type: ignore
1634+
langhelpers.repr_tuple_names(
1635+
self.enums # type: ignore
1636+
),
16151637
)
16161638
) from err
16171639

@@ -1671,7 +1693,9 @@ def as_generic(self, allow_nulltype: bool = False) -> TypeEngine[Any]:
16711693
self, self._generic_type_affinity, *args, _disable_warnings=True
16721694
)
16731695

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:
16751699
kw.setdefault("validate_strings", self.validate_strings)
16761700
kw.setdefault("name", self.name)
16771701
kw["_disable_warnings"] = True
@@ -1687,7 +1711,9 @@ def adapt_to_emulated(self, impltype: Type[TypeEngine[Any]], **kw: Any) -> TypeE
16871711
assert "_enums" in kw
16881712
return impltype(**kw)
16891713

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]:
16911717
kw["_enums"] = self._enums_argument
16921718
kw["_disable_warnings"] = True
16931719
return super().adapt(impltype, **kw)
@@ -1733,7 +1759,9 @@ def process(value: Any) -> Any:
17331759

17341760
return process
17351761

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]]:
17371765
parent_processor = super().bind_processor(dialect)
17381766

17391767
def process(value: Any) -> Any:
@@ -1744,7 +1772,9 @@ def process(value: Any) -> Any:
17441772

17451773
return process
17461774

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]]:
17481778
parent_processor = super().result_processor(dialect, coltype)
17491779

17501780
def process(value: _T) -> _T:
@@ -1942,7 +1972,7 @@ def _should_create_constraint(self, compiler: Compiled, **kw: Any) -> bool:
19421972
return False
19431973
return (
19441974
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
19461976
)
19471977

19481978
@util.preload_module("sqlalchemy.sql.schema")
@@ -2544,7 +2574,9 @@ class Comparator(Indexable.Comparator[_T], Concatenable.Comparator[_T]):
25442574

25452575
__slots__ = ()
25462576

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]]:
25482580
if not isinstance(index, str) and isinstance(
25492581
index, collections_abc.Sequence
25502582
):
@@ -2742,15 +2774,21 @@ def process(value: Any) -> Any:
27422774

27432775
def bind_processor(self, dialect: Dialect) -> Callable[[Any], Any]:
27442776
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+
)
27462780

27472781
return self._make_bind_processor(string_process, json_serializer)
27482782

27492783
def result_processor(
27502784
self, dialect: Dialect, coltype: _T
27512785
) -> 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+
)
27542792

27552793
def process(value: _T) -> Any:
27562794
if value is None:
@@ -3116,13 +3154,17 @@ def python_type(self) -> Type[List[Any]]:
31163154
def compare_values(self, x: _T, y: _T) -> Any:
31173155
return x == y
31183156

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:
31203160
"""Support SchemaEventTarget"""
31213161

31223162
if not outer and isinstance(self.item_type, SchemaEventTarget):
31233163
self.item_type._set_parent(column, **kw)
31243164

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:
31263168
"""Support SchemaEventTarget"""
31273169

31283170
super()._set_parent_with_dispatch(parent, outer=True)
@@ -3204,7 +3246,7 @@ class TupleType(TypeEngine[Tuple[Any, ...]]):
32043246

32053247
_is_tuple_type = True
32063248

3207-
types: List[TypeEngine[Any]]
3249+
types: Sequence[TypeEngine[Any]]
32083250

32093251
def __init__(self, *types: _TypeEngineArgument[Any]):
32103252
self._fully_typed = NULLTYPE not in types

0 commit comments

Comments
 (0)