diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2020-08-02 03:18:12 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2020-08-02 03:18:12 +0000 |
| commit | 0afa28ee3a9699f7a03fbcc8baf01ea873d0c425 (patch) | |
| tree | a7d300da26240b5b5bdb4b4e6b75e37cf0169a6e /lib/sqlalchemy | |
| parent | 5186bea969a0663f535a5a2daa7667a124b5b29f (diff) | |
| parent | 0721a6bede7222386b2a2508aac5590909fbb148 (diff) | |
| download | sqlalchemy-0afa28ee3a9699f7a03fbcc8baf01ea873d0c425.tar.gz | |
Merge "Genericize str() for types"
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 24 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/type_api.py | 7 |
2 files changed, 24 insertions, 7 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 61e26b003..a8bd1de33 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -4270,6 +4270,14 @@ class GenericTypeCompiler(TypeCompiler): class StrSQLTypeCompiler(GenericTypeCompiler): + def process(self, type_, **kw): + try: + _compiler_dispatch = type_._compiler_dispatch + except AttributeError: + return self._visit_unknown(type_, **kw) + else: + return _compiler_dispatch(self, **kw) + def __getattr__(self, key): if key.startswith("visit_"): return self._visit_unknown @@ -4277,7 +4285,21 @@ class StrSQLTypeCompiler(GenericTypeCompiler): raise AttributeError(key) def _visit_unknown(self, type_, **kw): - return "%s" % type_.__class__.__name__ + if type_.__class__.__name__ == type_.__class__.__name__.upper(): + return type_.__class__.__name__ + else: + return repr(type_) + + def visit_null(self, type_, **kw): + return "NULL" + + def visit_user_defined(self, type_, **kw): + try: + get_col_spec = type_.get_col_spec + except AttributeError: + return repr(type_) + else: + return get_col_spec(**kw) class IdentifierPreparer(object): diff --git a/lib/sqlalchemy/sql/type_api.py b/lib/sqlalchemy/sql/type_api.py index 2d23c56e1..1284ef515 100644 --- a/lib/sqlalchemy/sql/type_api.py +++ b/lib/sqlalchemy/sql/type_api.py @@ -626,12 +626,7 @@ class TypeEngine(Traversible): @util.preload_module("sqlalchemy.engine.default") def _default_dialect(self): default = util.preloaded.engine_default - if self.__class__.__module__.startswith("sqlalchemy.dialects"): - tokens = self.__class__.__module__.split(".")[0:3] - mod = ".".join(tokens) - return getattr(__import__(mod).dialects, tokens[-1]).dialect() - else: - return default.DefaultDialect() + return default.StrCompileDialect() def __str__(self): if util.py2k: |
