]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Spiffed up the deprecated decorators & @flipped 'em up top
authorJason Kirtland <jek@discorporate.us>
Wed, 16 Jul 2008 17:34:41 +0000 (17:34 +0000)
committerJason Kirtland <jek@discorporate.us>
Wed, 16 Jul 2008 17:34:41 +0000 (17:34 +0000)
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/orm/query.py
lib/sqlalchemy/orm/session.py
lib/sqlalchemy/schema.py
lib/sqlalchemy/util.py
test/engine/bind.py
test/orm/query.py
test/sql/select.py

index 6aafafdc191858b7e449bc89dd6f89ed5d95bd3b..7cf09829445c0cfdb0ede6681265d6d5612f6638 100644 (file)
@@ -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.
index f84a2d30e0b884334ac9a0c461afe18f3f31455d..9f91f29debc0bf35ee61f8b654757d03950782aa 100644 (file)
@@ -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):
index b63900a0deeb5d5c7967a0f89d53453b442f0058..f883ebc98e9179b9ae40f505dc9a01c214191439 100644 (file)
@@ -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``.
index 5742303d6da473e0ab372afd57c950db6bf92c7c..f6e55581f6c75543a9d656a1aeb21e208b967403 100644 (file)
@@ -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.
index 434ad4c7b16025dc2577064e21e5355ba12b2d33..d0027ebc4759748cc3fbc2470243a44eeb91eb40 100644 (file)
@@ -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
index 71043cb83b8540d6433c1299034fadd8c531f9a2..5b8605aada8f34462db6c9520e22865acd12c8f8 100644 (file)
@@ -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):
index 0c274efefdb46659de5efcab28a5d6a00aadac94..6ee9bbd9d89e29c4a99c1385bc887215e30c6e06 100644 (file)
@@ -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
index ddd8ede42fd309e3f88ba41d01848c492e56f35e..70d21798c64f682724200545d1694f6900cdf415 100644 (file)
@@ -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,