Add a new API:

warn_explicit(message, category, filename, lineno, module, registry)

The regular warn() call calculates a bunch of values and calls
warn_explicit() with these.

This will be used to issue better syntax warnings.
This commit is contained in:
Guido van Rossum 2001-02-28 21:43:40 +00:00
parent d6a1d79d16
commit 9e26318975
1 changed files with 10 additions and 0 deletions

View File

@ -34,6 +34,16 @@ def warn(message, category=None, stacklevel=1):
filename = module
# Quick test for common case
registry = globals.setdefault("__warningregistry__", {})
warn_explicit(message, category, filename, lineno, module, registry)
def warn_explicit(message, category, filename, lineno,
module=None, registry=None):
if module is None:
module = filename
if module[-3:].lower() == ".py":
module = module[:-3] # XXX What about leading pathname?
if registry is None:
registry = {}
key = (message, category, lineno)
if registry.get(key):
return