From: Steven Loria Date: Mon, 9 Sep 2019 14:48:29 +0000 (-0400) Subject: Remove unnecessary util.callable usage X-Git-Tag: rel_1_4_0b1~727 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=edcfc262a33bf8cbe509f2640e55d3361232c185;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Remove unnecessary util.callable usage Fixes: #4850 ### Description Removes usage of `util.callable`. ### Checklist This pull request is: - [ ] A documentation / typographical error fix - Good to go, no issue or tests are needed - [x] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #` in the commit message - please include tests. **Have a nice day!** Closes: #4851 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4851 Pull-request-sha: a0ccdff2cb74f5e944d8baccc269c382b591c8e2 Change-Id: I79918f44becbc5dbefdc7ff65128695c1cabed1d --- diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index 32dee79c69..f72b46c25c 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -1180,7 +1180,7 @@ class _AssociationList(_AssociationCollection): for func_name, func in list(locals().items()): if ( - util.callable(func) + callable(func) and func.__name__ == func_name and not func.__doc__ and hasattr(list, func_name) @@ -1355,7 +1355,7 @@ class _AssociationDict(_AssociationCollection): for func_name, func in list(locals().items()): if ( - util.callable(func) + callable(func) and func.__name__ == func_name and not func.__doc__ and hasattr(dict, func_name) @@ -1574,7 +1574,7 @@ class _AssociationSet(_AssociationCollection): for func_name, func in list(locals().items()): if ( - util.callable(func) + callable(func) and func.__name__ == func_name and not func.__doc__ and hasattr(set, func_name) diff --git a/lib/sqlalchemy/ext/orderinglist.py b/lib/sqlalchemy/ext/orderinglist.py index 16e0f1f2a4..5dbe58726b 100644 --- a/lib/sqlalchemy/ext/orderinglist.py +++ b/lib/sqlalchemy/ext/orderinglist.py @@ -119,7 +119,6 @@ start numbering at 1 or some other integer, provide ``count_from=1``. """ -from .. import util from ..orm.collections import collection from ..orm.collections import collection_adapter @@ -367,7 +366,7 @@ class OrderingList(list): for func_name, func in list(locals().items()): if ( - util.callable(func) + callable(func) and func.__name__ == func_name and not func.__doc__ and hasattr(list, func_name) diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index d50eab03ec..9d404e00d4 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -328,7 +328,7 @@ def create_proxied_attribute(descriptor): @util.memoized_property def comparator(self): - if util.callable(self._comparator): + if callable(self._comparator): self._comparator = self._comparator() if self._adapt_to_entity: self._comparator = self._comparator.adapt_to_entity( @@ -702,8 +702,10 @@ class AttributeImpl(object): if not passive & CALLABLES_OK: return PASSIVE_NO_RESULT - if self.accepts_scalar_loader and \ - key in state.expired_attributes: + if ( + self.accepts_scalar_loader + and key in state.expired_attributes + ): value = state._load_expired(state, passive) elif key in state.callables: callable_ = state.callables[key] diff --git a/lib/sqlalchemy/orm/collections.py b/lib/sqlalchemy/orm/collections.py index ae96a8c4da..4b096c1527 100644 --- a/lib/sqlalchemy/orm/collections.py +++ b/lib/sqlalchemy/orm/collections.py @@ -936,7 +936,7 @@ def _locate_roles_and_methods(cls): for supercls in cls.__mro__: for name, method in vars(supercls).items(): - if not util.callable(method): + if not callable(method): continue # note role declarations diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py index 46eec75eb9..63ec21099a 100644 --- a/lib/sqlalchemy/orm/relationships.py +++ b/lib/sqlalchemy/orm/relationships.py @@ -1824,7 +1824,7 @@ class RelationshipProperty(StrategizedProperty): class or aliased class tha is referred towards. """ - if util.callable(self.argument) and not isinstance( + if callable(self.argument) and not isinstance( self.argument, (type, mapperlib.Mapper) ): argument = self.argument() @@ -1888,7 +1888,7 @@ class RelationshipProperty(StrategizedProperty): "remote_side", ): attr_value = getattr(self, attr) - if util.callable(attr_value): + if callable(attr_value): setattr(self, attr, attr_value()) # remove "annotations" which are present if mapped class diff --git a/lib/sqlalchemy/sql/ddl.py b/lib/sqlalchemy/sql/ddl.py index ef6614b615..48d4bc9dcb 100644 --- a/lib/sqlalchemy/sql/ddl.py +++ b/lib/sqlalchemy/sql/ddl.py @@ -258,7 +258,7 @@ class DDLElement(roles.DDLRole, Executable, _DDLCompiles): def _check_ddl_on(self, on): if on is not None and ( not isinstance(on, util.string_types + (tuple, list, set)) - and not util.callable(on) + and not callable(on) ): raise exc.ArgumentError( "Expected the name of a database dialect, a tuple " diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index f0a6977285..d5ee1057b8 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -2222,13 +2222,13 @@ class ColumnDefault(DefaultGenerator): raise exc.ArgumentError( "ColumnDefault may not be a server-side default type." ) - if util.callable(arg): + if callable(arg): arg = self._maybe_wrap_callable(arg) self.arg = arg @util.memoized_property def is_callable(self): - return util.callable(self.arg) + return callable(self.arg) @util.memoized_property def is_clause_element(self): @@ -4211,7 +4211,7 @@ class MetaData(SchemaItem): for name, schname in zip(available, available_w_schema) if extend_existing or schname not in current ] - elif util.callable(only): + elif callable(only): load = [ name for name, schname in zip(available, available_w_schema) diff --git a/lib/sqlalchemy/sql/type_api.py b/lib/sqlalchemy/sql/type_api.py index 11407ad2e1..9c5f5dd475 100644 --- a/lib/sqlalchemy/sql/type_api.py +++ b/lib/sqlalchemy/sql/type_api.py @@ -1461,7 +1461,7 @@ def to_instance(typeobj, *arg, **kw): if typeobj is None: return NULLTYPE - if util.callable(typeobj): + if callable(typeobj): return typeobj(*arg, **kw) else: return typeobj diff --git a/lib/sqlalchemy/testing/assertsql.py b/lib/sqlalchemy/testing/assertsql.py index 55f4dc2abb..6a654df1ec 100644 --- a/lib/sqlalchemy/testing/assertsql.py +++ b/lib/sqlalchemy/testing/assertsql.py @@ -170,7 +170,7 @@ class CompiledSQL(SQLMatchRule): def _all_params(self, context): if self.params: - if util.callable(self.params): + if callable(self.params): params = self.params(context) else: params = self.params diff --git a/lib/sqlalchemy/testing/exclusions.py b/lib/sqlalchemy/testing/exclusions.py index d205354cff..edb9caa168 100644 --- a/lib/sqlalchemy/testing/exclusions.py +++ b/lib/sqlalchemy/testing/exclusions.py @@ -208,7 +208,7 @@ class Predicate(object): ) return SpecPredicate(db, op, spec, description=description) - elif util.callable(predicate): + elif callable(predicate): return LambdaPredicate(predicate, description) else: assert False, "unknown predicate type: %s" % predicate diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index b655a55f3c..8cfaea26e2 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -158,14 +158,8 @@ if py3k: def ue(s): return s - if py32: - callable = callable # noqa - else: - - def callable(fn): # noqa - return hasattr(fn, "__call__") - - + # Unused. Kept for backwards compatibility. + callable = callable # noqa else: import base64 import ConfigParser as configparser # noqa