diff options
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/query.py | 7 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/session.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/schema.py | 12 | ||||
-rw-r--r-- | lib/sqlalchemy/util.py | 26 | ||||
-rw-r--r-- | test/engine/bind.py | 2 | ||||
-rw-r--r-- | test/orm/query.py | 2 | ||||
-rw-r--r-- | test/sql/select.py | 2 |
8 files changed, 32 insertions, 27 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 6aafafdc1..7cf098294 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -466,10 +466,10 @@ class Compiled(object): raise NotImplementedError() + @util.deprecated('Deprecated. Use construct_params(). ' + '(supports Unicode key names.)') def get_params(self, **params): - """Use construct_params(). (supports unicode names)""" return self.construct_params(params) - get_params = util.deprecated()(get_params) def construct_params(self, params): """Return the bind params for this compiled object. diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index f84a2d30e..9f91f29de 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -411,6 +411,9 @@ class Query(object): key = self._only_mapper_zero().identity_key_from_primary_key(ident) return self._get(key, ident) + @classmethod + @util.deprecated('Deprecated. Use sqlalchemy.orm.with_parent ' + 'in conjunction with filter().') def query_from_parent(cls, instance, property, **kwargs): """Return a new Query with criterion corresponding to a parent instance. @@ -429,16 +432,12 @@ class Query(object): all extra keyword arguments are propagated to the constructor of Query. - deprecated. use sqlalchemy.orm.with_parent in conjunction with - filter(). - """ mapper = object_mapper(instance) prop = mapper.get_property(property, resolve_synonyms=True) target = prop.mapper criterion = prop.compare(operators.eq, instance, value_is_parent=True) return Query(target, **kwargs).filter(criterion) - query_from_parent = classmethod(util.deprecated(None, False)(query_from_parent)) @_generative() def correlate(self, *args): diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index b63900a0d..f883ebc98 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -1043,6 +1043,7 @@ class Session(object): self._deleted.pop(state, None) del state.session_id + @util.pending_deprecation('0.5.x', "Use session.add()") def save(self, instance, entity_name=None): """Add a transient (unsaved) instance to this ``Session``. @@ -1056,7 +1057,6 @@ class Session(object): state = _state_for_unsaved_instance(instance, entity_name) self._save_impl(state) self._cascade_save_or_update(state, entity_name) - save = util.pending_deprecation('0.5.x', "Use session.add()")(save) def _save_without_cascade(self, instance, entity_name=None): """Used by scoping.py to save on init without cascade.""" @@ -1064,6 +1064,7 @@ class Session(object): state = _state_for_unsaved_instance(instance, entity_name, create=True) self._save_impl(state) + @util.pending_deprecation('0.5.x', "Use session.add()") def update(self, instance, entity_name=None): """Bring a detached (saved) instance into this ``Session``. @@ -1081,7 +1082,6 @@ class Session(object): raise exc.UnmappedInstanceError(instance, entity_name) self._update_impl(state) self._cascade_save_or_update(state, entity_name) - update = util.pending_deprecation('0.5.x', "Use session.add()")(update) def add(self, instance, entity_name=None): """Add the given instance into this ``Session``. diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 5742303d6..f6e55581f 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -1483,12 +1483,11 @@ class MetaData(SchemaItem): return self._bind is not None - # @deprecated + @util.deprecated('Deprecated. Use ``metadata.bind = <engine>`` or ' + '``metadata.bind = <url>``.') def connect(self, bind, **kwargs): """Bind this MetaData to an Engine. - Use ``metadata.bind = <engine>`` or ``metadata.bind = <url>``. - bind A string, ``URL``, ``Engine`` or ``Connection`` instance. If a string or ``URL``, will be passed to ``create_engine()`` along with @@ -1504,7 +1503,6 @@ class MetaData(SchemaItem): self._bind = create_engine(bind, **kwargs) else: self._bind = bind - connect = util.deprecated()(connect) def bind(self): """An Engine or Connection to which this MetaData is bound. @@ -1724,12 +1722,11 @@ class ThreadLocalMetaData(MetaData): self.__engines = {} super(ThreadLocalMetaData, self).__init__() - # @deprecated + @util.deprecated('Deprecated. Use ``metadata.bind = <engine>`` or ' + '``metadata.bind = <url>``.') def connect(self, bind, **kwargs): """Bind to an Engine in the caller's thread. - Use ``metadata.bind=<engine>`` or ``metadata.bind=<url>``. - bind A string, ``URL``, ``Engine`` or ``Connection`` instance. If a string or ``URL``, will be passed to ``create_engine()`` along with @@ -1749,7 +1746,6 @@ class ThreadLocalMetaData(MetaData): engine = create_engine(bind, **kwargs) bind = engine self._bind_to(bind) - connect = util.deprecated()(connect) def bind(self): """The bound Engine or Connection for this thread. diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index 434ad4c7b..d0027ebc4 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -1467,15 +1467,25 @@ def pending_deprecation(version, message=None, def _decorate_with_warning(func, wtype, message, docstring_header=None): """Wrap a function with a warnings.warn and augmented docstring.""" - def func_with_warning(*args, **kwargs): - warnings.warn(wtype(message), stacklevel=2) - return func(*args, **kwargs) + @decorator + def warned(fn, *args, **kwargs): + warnings.warn(wtype(message), stacklevel=3) + return fn(*args, **kwargs) doc = func.__doc__ is not None and func.__doc__ or '' if docstring_header is not None: - doc = '\n'.join((docstring_header.rstrip(), doc)) - - func_with_warning.__doc__ = doc - func_with_warning.__dict__.update(func.__dict__) + docstring_header %= dict(func=func.__name__) + docs = doc and doc.expandtabs().split('\n') or [] + indent = '' + for line in docs[1:]: + text = line.lstrip() + if text: + indent = line[0:len(line) - len(text)] + break + point = min(len(docs), 1) + docs.insert(point, '\n' + indent + docstring_header.rstrip()) + doc = '\n'.join(docs) - return function_named(func_with_warning, func.__name__) + decorated = warned(func) + decorated.__doc__ = doc + return decorated diff --git a/test/engine/bind.py b/test/engine/bind.py index 71043cb83..5b8605aad 100644 --- a/test/engine/bind.py +++ b/test/engine/bind.py @@ -94,7 +94,7 @@ class BindTest(testing.TestBase): "assign this Table's .metadata.bind to enable implicit " "execution.") - @testing.uses_deprecated('//connect') + @testing.uses_deprecated() def test_create_drop_bound(self): for meta in (MetaData,ThreadLocalMetaData): diff --git a/test/orm/query.py b/test/orm/query.py index 0c274efef..6ee9bbd9d 100644 --- a/test/orm/query.py +++ b/test/orm/query.py @@ -648,7 +648,7 @@ class ParentTest(QueryTest): assert [Order(description="order 1"), Order(description="order 3"), Order(description="order 5")] == o # test static method - @testing.uses_deprecated(".*query_from_parent") + @testing.uses_deprecated(".*Use sqlalchemy.orm.with_parent") def go(): o = Query.query_from_parent(u1, property='orders', session=sess).all() assert [Order(description="order 1"), Order(description="order 3"), Order(description="order 5")] == o diff --git a/test/sql/select.py b/test/sql/select.py index ddd8ede42..70d21798c 100644 --- a/test/sql/select.py +++ b/test/sql/select.py @@ -962,7 +962,7 @@ UNION SELECT mytable.myid FROM mytable" self.assert_compile(s, "SELECT foo, bar UNION SELECT foo, bar UNION (SELECT foo, bar UNION SELECT foo, bar)") - @testing.uses_deprecated('//get_params') + @testing.uses_deprecated() def test_binds(self): for ( stmt, |