diff options
author | Jason Kirtland <jek@discorporate.us> | 2008-01-11 01:28:43 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2008-01-11 01:28:43 +0000 |
commit | 8dd825b413276025b0f27d2ed7e5b93ba81a5b9c (patch) | |
tree | 4a13aec5f61d1a934a3b4a527e9bdaf7f5cfc9ce /lib/sqlalchemy/util.py | |
parent | 3e9df22546cb4c7af0ece290f4f57a377516f142 (diff) | |
download | sqlalchemy-8dd825b413276025b0f27d2ed7e5b93ba81a5b9c.tar.gz |
- Warnings are now issued as SAWarning instead of RuntimeWarning; util.warn() wraps this up.
- SADeprecationWarning has moved to exceptions. An alias remains in logging until 0.5.
Diffstat (limited to 'lib/sqlalchemy/util.py')
-rw-r--r-- | lib/sqlalchemy/util.py | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index 5c391ac3d..05990e4ed 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -7,7 +7,7 @@ import itertools, sys, warnings, sets, weakref import __builtin__ -from sqlalchemy import exceptions, logging +from sqlalchemy import exceptions try: import thread, threading @@ -45,9 +45,8 @@ try: except ImportError: def Decimal(arg): if Decimal.warn: - warnings.warn(RuntimeWarning( - "True Decimal types not available on this Python, " - "falling back to floats.")) + warn("True Decimal types not available on this Python, " + "falling back to floats.") Decimal.warn = False return float(arg) Decimal.warn = True @@ -241,7 +240,7 @@ def warn_exception(func, *args, **kwargs): try: return func(*args, **kwargs) except: - warnings.warn(RuntimeWarning("%s('%s') ignored" % sys.exc_info()[0:2])) + warn("%s('%s') ignored" % sys.exc_info()[0:2]) class SimpleProperty(object): """A *default* property accessor.""" @@ -839,18 +838,35 @@ class ScopedRegistry(object): def _get_key(self): return self.scopefunc() +def warn(msg): + if isinstance(msg, basestring): + warnings.warn(msg, exceptions.SAWarning, stacklevel=3) + else: + warnings.warn(msg, stacklevel=3) def warn_deprecated(msg): - warnings.warn(logging.SADeprecationWarning(msg), stacklevel=3) + warnings.warn(msg, exceptions.SADeprecationWarning, stacklevel=3) def deprecated(func, message=None, add_deprecation_to_docstring=True): + """Decorates a function and issues a deprecation warning on use. + + message + If provided, issue message in the warning. A sensible default + is used if not provided. + + add_deprecation_to_docstring + Default True. If False, the wrapped function's __doc__ is left + as-is. If True, the 'message' is prepended to the docs if + provided, or sensible default if message is omitted. + """ + if message is not None: warning = message % dict(func=func.__name__) else: warning = "Call to deprecated function %s" % func.__name__ def func_with_warning(*args, **kwargs): - warnings.warn(logging.SADeprecationWarning(warning), + warnings.warn(exceptions.SADeprecationWarning(warning), stacklevel=2) return func(*args, **kwargs) |