diff options
author | Jason Kirtland <jek@discorporate.us> | 2008-07-16 17:34:41 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2008-07-16 17:34:41 +0000 |
commit | b155b60280828b23d6b7f165f7d1c0b9e51b4250 (patch) | |
tree | 2449c1719e93424a623fdcdaffb46c70874e470c /lib/sqlalchemy/util.py | |
parent | 437dd22d49e69aa7555b37788ad5ca532a2f33c0 (diff) | |
download | sqlalchemy-b155b60280828b23d6b7f165f7d1c0b9e51b4250.tar.gz |
- Spiffed up the deprecated decorators & @flipped 'em up top
Diffstat (limited to 'lib/sqlalchemy/util.py')
-rw-r--r-- | lib/sqlalchemy/util.py | 26 |
1 files changed, 18 insertions, 8 deletions
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 |