diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-01-02 11:37:20 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-01-02 11:37:20 -0500 |
| commit | 0755114f75dc765c5f7c61483323338ef477dd14 (patch) | |
| tree | 092f970f7bf384019fcd7fc1c8a22af63961d73f /lib/sqlalchemy | |
| parent | a94f2f81afc859ea4553037cc12734311c8328b0 (diff) | |
| download | sqlalchemy-0755114f75dc765c5f7c61483323338ef477dd14.tar.gz | |
- remove the test against bindparam('x') for the bind/result SQL expressions
- apply a consistent approach to the "see if method X is implemented" conditionals
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/types.py | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index f5c928e5f..ce64bb83e 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -149,8 +149,15 @@ class TypeEngine(AbstractType): @util.memoized_property def _has_column_expression(self): - """memoized boolean, check if column_expression is implemented.""" - return self.column_expression(column('x')) is not None + """memoized boolean, check if column_expression is implemented. + + Allows the method to be skipped for the vast majority of expression + types that don't use this feature. + + """ + + return self.__class__.column_expression.func_code \ + is not TypeEngine.column_expression.func_code def bind_expression(self, bindvalue): """"Given a bind value (i.e. a :class:`.BindParameter` instance), @@ -180,8 +187,15 @@ class TypeEngine(AbstractType): @util.memoized_property def _has_bind_expression(self): - """memoized boolean, check if bind_expression is implemented.""" - return self.bind_expression(bindparam('x')) is not None + """memoized boolean, check if bind_expression is implemented. + + Allows the method to be skipped for the vast majority of expression + types that don't use this feature. + + """ + + return self.__class__.bind_expression.func_code \ + is not TypeEngine.bind_expression.func_code def compare_values(self, x, y): """Compare two values for equality.""" @@ -699,6 +713,19 @@ class TypeDecorator(TypeEngine): raise NotImplementedError() + @util.memoized_property + def _has_bind_processor(self): + """memoized boolean, check if process_bind_param is implemented. + + Allows the base process_bind_param to raise + NotImplementedError without needing to test an expensive + exception throw. + + """ + + return self.__class__.process_bind_param.func_code \ + is not TypeDecorator.process_bind_param.func_code + def bind_processor(self, dialect): """Provide a bound value processing function for the given :class:`.Dialect`. @@ -718,8 +745,7 @@ class TypeDecorator(TypeEngine): :meth:`result_processor` method of this class. """ - if self.__class__.process_bind_param.func_code \ - is not TypeDecorator.process_bind_param.func_code: + if self._has_bind_processor: process_param = self.process_bind_param impl_processor = self.impl.bind_processor(dialect) if impl_processor: @@ -734,6 +760,18 @@ class TypeDecorator(TypeEngine): else: return self.impl.bind_processor(dialect) + @util.memoized_property + def _has_result_processor(self): + """memoized boolean, check if process_result_value is implemented. + + Allows the base process_result_value to raise + NotImplementedError without needing to test an expensive + exception throw. + + """ + return self.__class__.process_result_value.func_code \ + is not TypeDecorator.process_result_value.func_code + def result_processor(self, dialect, coltype): """Provide a result value processing function for the given :class:`.Dialect`. @@ -754,8 +792,7 @@ class TypeDecorator(TypeEngine): :meth:`bind_processor` method of this class. """ - if self.__class__.process_result_value.func_code \ - is not TypeDecorator.process_result_value.func_code: + if self._has_result_processor: process_value = self.process_result_value impl_processor = self.impl.result_processor(dialect, coltype) |
