else:
return self.__class__
- @classmethod
- def _is_generic_type(cls):
- n = cls.__name__
- return n.upper() != n
-
def _generic_type_affinity(self):
+ best_camelcase = None
+ best_uppercase = None
+
+ if not isinstance(self, (TypeEngine, UserDefinedType)):
+ return self.__class__
for t in self.__class__.__mro__:
if (
"sqlalchemy.sql.sqltypes",
"sqlalchemy.sql.type_api",
)
- and hasattr(t, '_is_generic_type') and t._is_generic_type()
+ and issubclass(t, TypeEngine)
+ and t is not TypeEngine
):
- if t in (TypeEngine, UserDefinedType):
- return NULLTYPE.__class__
- return t
- else:
- return self.__class__
+ if t.__name__.isupper() and not best_uppercase:
+ best_uppercase = t
+ elif not t.__name__.isupper() and not best_camelcase:
+ best_camelcase = t
+
+ return best_camelcase or best_uppercase or NULLTYPE.__class__
def as_generic(self):
"""Return an instance of the generic type corresponding to this type"""
import os
import sqlalchemy as sa
+import sqlalchemy.dialects.postgresql as pg
from sqlalchemy import and_
from sqlalchemy import ARRAY
from sqlalchemy import BigInteger
(VARCHAR(length=100), String(length=100)),
(NVARCHAR(length=100), Unicode(length=100)),
(DATE(), Date()),
+ (pg.JSON(), sa.JSON()),
+ (pg.ARRAY(sa.String), sa.ARRAY(sa.String)),
)
def test_as_generic(self, t1, t2):
assert repr(t1.as_generic()) == repr(t2)