Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

applied fix to deprecated decorator to warn only once (thanks Dan)

Pablo Hoffman4f06f6ef41d9
diff --git a/scrapy/utils/decorator.py b/scrapy/utils/decorator.py
index 74f393377..e49ea1c73 100644
--- a/scrapy/utils/decorator.py
+++ b/scrapy/utils/decorator.py
@@ -1,4 +1,5 @@
import warnings
+from functools import wraps
def deprecated(use_instead=None):
@@ -6,19 +7,20 @@ def deprecated(use_instead=None):
as deprecated. It will result in a warning being emitted
when the function is used."""
- def wraps(func):
+ def wrapped(func):
+ @wraps(func)
def new_func(*args, **kwargs):
message = "Call to deprecated function %s." % func.__name__
if use_instead:
message += " Use %s instead." % use_instead
- warnings.warn_explicit(
- message,
+ warnings.warn_explicit(message,
category=DeprecationWarning,
filename=func.func_code.co_filename,
- lineno=func.func_code.co_firstlineno + 1
- )
+ lineno=func.func_code.co_firstlineno + 1,
+ registry=func.func_globals.setdefault('__warningregistry__', \
+ {}),
+ module_globals=func.func_globals)
return func(*args, **kwargs)
return new_func
- return wraps
-
+ return wrapped