Skip to content

Commit

Permalink
Warn deprecation in Promise.promisify instead of full deprecation.
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Apr 12, 2017
1 parent 15b51b8 commit 1f51d04
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion promise/promise.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .async_ import Async
from .compat import (Future, ensure_future, iscoroutine, # type: ignore
iterate_promise)
from .utils import deprecated, integer_types, string_types, text_type, binary_type
from .utils import deprecated, integer_types, string_types, text_type, binary_type, warn
from .context import Context
from .promise_list import PromiseList
from .scheduler import SyncScheduler
Expand Down Expand Up @@ -680,6 +680,10 @@ def resolve(cls, obj):

@classmethod
def promisify(cls, f):
if not callable(f):
warn("Promise.promisify is now a function decorator, please use Promise.resolve instead.")
return cls.resolve(f)

@wraps(f)
def wrapper(*args, **kwargs):
def executor(resolve, reject):
Expand Down
10 changes: 7 additions & 3 deletions promise/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
import sys


def warn(msg):
warnings.simplefilter('always', DeprecationWarning) # turn off filter
warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
warnings.simplefilter('default', DeprecationWarning) # reset filter


class deprecated(object):

def __init__(self, reason, name=None):
Expand All @@ -27,9 +33,7 @@ def __call__(self, cls_or_func):

@functools.wraps(cls_or_func)
def new_func(*args, **kwargs):
warnings.simplefilter('always', DeprecationWarning) # turn off filter
warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
warnings.simplefilter('default', DeprecationWarning) # reset filter
warn(msg)
return cls_or_func(*args, **kwargs)

return new_func
Expand Down

0 comments on commit 1f51d04

Please sign in to comment.