summaryrefslogtreecommitdiffstats
path: root/Lib/warnings.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2008-05-05 16:57:38 (GMT)
committerBrett Cannon <bcannon@gmail.com>2008-05-05 16:57:38 (GMT)
commit9c19bc62478e1cd732623abfdf701239d2f860ce (patch)
tree613a3c9faf01bb0ae185708d962203d7792046d3 /Lib/warnings.py
parent8a232cc385343c17d9f615f0aff49fc378bdebae (diff)
downloadcpython-9c19bc62478e1cd732623abfdf701239d2f860ce.zip
cpython-9c19bc62478e1cd732623abfdf701239d2f860ce.tar.gz
cpython-9c19bc62478e1cd732623abfdf701239d2f860ce.tar.bz2
Remove the use of 'inspect' from 'warnings' for detected deprecated use of the
showwarning API. Turns out 'inspect' uses 'operator' which is an extension module. That's a problem when it has not been built yet by setup.py.
Diffstat (limited to 'Lib/warnings.py')
-rw-r--r--Lib/warnings.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/Lib/warnings.py b/Lib/warnings.py
index cefa961..d9e6e44 100644
--- a/Lib/warnings.py
+++ b/Lib/warnings.py
@@ -3,7 +3,6 @@
# Note: function level imports should *not* be used
# in this module as it may cause import lock deadlock.
# See bug 683658.
-import inspect
import linecache
import sys
import types
@@ -262,16 +261,24 @@ def warn_explicit(message, category, filename, lineno,
raise RuntimeError(
"Unrecognized action (%r) in warnings.filters:\n %s" %
(action, item))
- # Print message and context
- if inspect.isfunction(showwarning):
- arg_spec = inspect.getargspec(showwarning)
- if 'line' not in arg_spec.args:
+ # Warn if showwarning() does not support the 'line' argument.
+ # Don't use 'inspect' as it relies on an extension module, which break the
+ # build thanks to 'warnings' being imported by setup.py.
+ fxn_code = None
+ if hasattr(showwarning, 'func_code'):
+ fxn_code = showwarning.func_code
+ elif hasattr(showwarning, '__func__'):
+ fxn_code = showwarning.__func__.func_code
+ if fxn_code:
+ args = fxn_code.co_varnames[:fxn_code.co_argcount]
+ if 'line' not in args:
showwarning_msg = ("functions overriding warnings.showwarning() "
"must support the 'line' argument")
if message == showwarning_msg:
_show_warning(message, category, filename, lineno)
else:
warn(showwarning_msg, DeprecationWarning)
+ # Print message and context
showwarning(message, category, filename, lineno)