mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-26 10:43:43 +00:00
applied fix to deprecated decorator to warn only once (thanks Dan)
This commit is contained in:
parent
41036af643
commit
4f06f6ef41
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user