Пример #1
0
 def decorator(wrapped, instance, args, kwargs):
     if old_name in kwargs:
         _utils.deprecation(out_message,
                            stacklevel=stacklevel, category=category)
         if replace:
             kwargs.setdefault(new_name, kwargs.pop(old_name))
     return wrapped(*args, **kwargs)
Пример #2
0
def deprecate(prefix, postfix=None, message=None,
              version=None, removal_version=None,
              stacklevel=3, category=DeprecationWarning):
    """Helper to deprecate some thing using generated message format.

    :param prefix: prefix string used as the prefix of the output message
    :param postfix: postfix string used as the postfix of the output message
    :param message: message string used as ending contents of the deprecate
                    message
    :param version: version string (represents the version this
                    deprecation was created in)
    :param removal_version: version string (represents the version this
                            deprecation will be removed in); a string of '?'
                            will denote this will be removed in some future
                            unknown version
    :param stacklevel: stacklevel used in the :func:`warnings.warn` function
                       to locate where the users code is in the
                       :func:`warnings.warn` call
    :param category: the :mod:`warnings` category to use, defaults to
                     :py:class:`DeprecationWarning` if not provided
    """
    out_message = _utils.generate_message(prefix, postfix=postfix,
                                          version=version, message=message,
                                          removal_version=removal_version)
    _utils.deprecation(out_message, stacklevel=stacklevel,
                       category=category)
Пример #3
0
 def __delete__(self, obj):
     if self.fdel is None:
         raise AttributeError("can't delete attribute")
     out_message = self._fetch_message_from_cache('delete')
     _utils.deprecation(out_message, stacklevel=self.stacklevel,
                        category=self.category)
     self.fdel(obj)
Пример #4
0
def removed_module(module, replacement=None, message=None,
                   version=None, removal_version=None, stacklevel=3):
    """Helper to be called inside a module to emit a deprecation warning

    :param str replacment: A location (or information about) of any potential
                           replacement for the removed module (if applicable)
    :param str message: A message to include in the deprecation warning
    :param str version: Specify what version the removed module is present in
    :param str removal_version: What version the module will be removed. If
                                '?' is used this implies an undefined future
                                version
    :param int stacklevel: How many entries deep in the call stack before
                           ignoring
    """
    if inspect.ismodule(module):
        module_name = _get_module_name(module)
    elif isinstance(module, six.string_types):
        module_name = module
    else:
        _qual, type_name = _get_qualified_name(type(module))
        raise TypeError("Unexpected module type '%s' (expected string or"
                        " module type only)" % type_name)
    prefix = "The '%s' module usage is deprecated" % module_name
    if replacement:
        postfix = ", please use %s instead" % replacement
    else:
        postfix = None
    out_message = _utils.generate_message(prefix,
                                          postfix=postfix, message=message,
                                          version=version,
                                          removal_version=removal_version)
    _utils.deprecation(out_message, stacklevel)
Пример #5
0
 def wrapper(*args, **kwargs):
     explicit_params = set(varnames[: len(args)] + list(kwargs.keys()))
     allparams = set(varnames)
     default_params = set(allparams - explicit_params)
     if name in default_params:
         _utils.deprecation(out_message, stacklevel=stacklevel, category=category)
     return f(*args, **kwargs)
Пример #6
0
 def __set__(self, obj, value):
     if self.fset is None:
         raise AttributeError("can't set attribute")
     out_message = self._fetch_message_from_cache('set')
     _utils.deprecation(out_message, stacklevel=self.stacklevel,
                        category=self.category)
     self.fset(obj, value)
Пример #7
0
 def wrapper(*args, **kwargs):
     if old_name in kwargs:
         _utils.deprecation(out_message,
                            stacklevel=stacklevel, category=category)
         if replace:
             kwargs.setdefault(new_name, kwargs.pop(old_name))
     return f(*args, **kwargs)
Пример #8
0
 def wrapper(*args, **kwargs):
     if old_name in kwargs:
         _utils.deprecation(out_message,
                            stacklevel=stacklevel,
                            category=category)
         if replace:
             kwargs.setdefault(new_name, kwargs.pop(old_name))
     return f(*args, **kwargs)
Пример #9
0
 def decorator(wrapped, instance, args, kwargs):
     if old_name in kwargs:
         _utils.deprecation(out_message,
                            stacklevel=stacklevel,
                            category=category)
         if replace:
             kwargs.setdefault(new_name, kwargs.pop(old_name))
     return wrapped(*args, **kwargs)
Пример #10
0
 def __get__(self, obj, value):
     if obj is None:
         return self
     if self.fget is None:
         raise AttributeError("unreadable attribute")
     out_message = self._fetch_message_from_cache("get")
     _utils.deprecation(out_message, stacklevel=self.stacklevel, category=self.category)
     return self.fget(obj)
Пример #11
0
 def wrapper(wrapped, instance, args, kwargs):
     explicit_params = set(varnames[:len(args)] + list(kwargs.keys()))
     allparams = set(varnames)
     default_params = set(allparams - explicit_params)
     if name in default_params:
         _utils.deprecation(out_message,
                            stacklevel=stacklevel,
                            category=category)
     return wrapped(*args, **kwargs)
Пример #12
0
 def __get__(self, obj, value):
     if obj is None:
         return self
     if self.fget is None:
         raise AttributeError("unreadable attribute")
     out_message = self._fetch_message_from_cache('get')
     _utils.deprecation(out_message, stacklevel=self.stacklevel,
                        category=self.category)
     return self.fget(obj)
Пример #13
0
 def __get__(self, instance, owner):
     _utils.deprecation(self._message,
                        stacklevel=self._stacklevel,
                        category=self._category)
     # This handles the descriptor being applied on a
     # instance or a class and makes both work correctly...
     if instance is not None:
         real_owner = instance
     else:
         real_owner = owner
     return getattr(real_owner, self._new_name)
Пример #14
0
 def __get__(self, instance, owner):
     _utils.deprecation(self._message,
                        stacklevel=self._stacklevel,
                        category=self._category)
     # This handles the descriptor being applied on a
     # instance or a class and makes both work correctly...
     if instance is not None:
         real_owner = instance
     else:
         real_owner = owner
     return getattr(real_owner, self._new_name)
Пример #15
0
 def wrapper(f, instance, args, kwargs):
     qualified, f_name = _utils.get_qualified_name(f)
     if qualified:
         if inspect.isclass(f):
             prefix_pre = "Using class"
             thing_post = ''
         else:
             prefix_pre = "Using function/method"
             thing_post = '()'
     if not qualified:
         prefix_pre = "Using function/method"
         base_name = None
         if instance is None:
             # Decorator was used on a class
             if inspect.isclass(f):
                 prefix_pre = "Using class"
                 thing_post = ''
                 module_name = _get_module_name(inspect.getmodule(f))
                 if module_name == '__main__':
                     f_name = _utils.get_class_name(
                         f, fully_qualified=False)
                 else:
                     f_name = _utils.get_class_name(
                         f, fully_qualified=True)
             # Decorator was a used on a function
             else:
                 thing_post = '()'
                 module_name = _get_module_name(inspect.getmodule(f))
                 if module_name != '__main__':
                     f_name = _utils.get_callable_name(f)
         # Decorator was used on a classmethod or instancemethod
         else:
             thing_post = '()'
             base_name = _utils.get_class_name(instance,
                                               fully_qualified=False)
         if base_name:
             thing_name = ".".join([base_name, f_name])
         else:
             thing_name = f_name
     else:
         thing_name = f_name
     if thing_post:
         thing_name += thing_post
     prefix = prefix_pre + " '%s' is deprecated" % (thing_name)
     out_message = _utils.generate_message(
         prefix,
         version=version,
         removal_version=removal_version,
         message=message)
     _utils.deprecation(out_message,
                        stacklevel=stacklevel, category=category)
     return f(*args, **kwargs)
Пример #16
0
 def wrapper(f, instance, args, kwargs):
     qualified, f_name = _utils.get_qualified_name(f)
     if qualified:
         if inspect.isclass(f):
             prefix_pre = "Using class"
             thing_post = ''
         else:
             prefix_pre = "Using function/method"
             thing_post = '()'
     if not qualified:
         prefix_pre = "Using function/method"
         base_name = None
         if instance is None:
             # Decorator was used on a class
             if inspect.isclass(f):
                 prefix_pre = "Using class"
                 thing_post = ''
                 module_name = _get_qualified_name(inspect.getmodule(f))
                 if module_name == '__main__':
                     f_name = _utils.get_class_name(
                         f, fully_qualified=False)
                 else:
                     f_name = _utils.get_class_name(
                         f, fully_qualified=True)
             # Decorator was a used on a function
             else:
                 thing_post = '()'
                 module_name = _get_qualified_name(inspect.getmodule(f))
                 if module_name != '__main__':
                     f_name = _utils.get_callable_name(f)
         # Decorator was used on a classmethod or instancemethod
         else:
             thing_post = '()'
             base_name = _utils.get_class_name(instance,
                                               fully_qualified=False)
         if base_name:
             thing_name = ".".join([base_name, f_name])
         else:
             thing_name = f_name
     else:
         thing_name = f_name
     if thing_post:
         thing_name += thing_post
     prefix = prefix_pre + " '%s' is deprecated" % (thing_name)
     out_message = _utils.generate_message(
         prefix,
         version=version,
         removal_version=removal_version,
         message=message)
     _utils.deprecation(out_message,
                        stacklevel=stacklevel, category=category)
     return f(*args, **kwargs)
Пример #17
0
 def wrapper(self, *args, **kwargs):
     base_name = reflection.get_class_name(self, fully_qualified=False)
     if fully_qualified:
         old_name = old_attribute_name
     else:
         old_name = ".".join((base_name, old_attribute_name))
     new_name = ".".join((base_name, new_attribute_name))
     prefix = _KIND_MOVED_PREFIX_TPL % (kind, old_name, new_name)
     out_message = _utils.generate_message(
         prefix, message=message,
         version=version, removal_version=removal_version)
     _utils.deprecation(out_message, stacklevel=stacklevel)
     return f(self, *args, **kwargs)
    def wrapper(f, instance, args, kwargs):
        try:
            # Prefer the py3.x name (if we can get at it...)
            f_name = f.__qualname__
            qualified = True
            if inspect.isclass(f):
                _prefix_pre = "Using class"
            else:
                _prefix_pre = "Using function/method"
        except AttributeError:
            f_name = f.__name__
            qualified = False

        if not qualified:
            _prefix_pre = "Using function/method"
            if instance is None:
                # Decorator was used on a class
                if inspect.isclass(f):
                    _prefix_pre = "Using class"
                    module_name = inspect.getmodule(f).__name__
                    if module_name == '__main__':
                        f_name = reflection.get_class_name(
                            f, fully_qualified=False)
                    else:
                        f_name = reflection.get_class_name(
                            f, fully_qualified=True)
                    base_name = None
                # Decorator was a used on a function
                else:
                    module_name = inspect.getmodule(f).__name__
                    if module_name != '__main__':
                        f_name = reflection.get_callable_name(f)
                    base_name = None
            # Decorator was used on a classmethod or instancemethod
            else:
                base_name = reflection.get_class_name(instance,
                                                      fully_qualified=False)
            if base_name:
                function_name = ".".join([base_name, f_name])
            else:
                function_name = f_name
        else:
            function_name = f_name
        _prefix = _prefix_pre + " %s is deprecated" % function_name
        out_message = _utils.generate_message(_prefix,
                                              version=version,
                                              removal_version=removal_version,
                                              message=message)
        _utils.deprecation(out_message, stacklevel)
        return f(*args, **kwargs)
Пример #19
0
 def wrapper(self, *args, **kwargs):
     base_name = reflection.get_class_name(self, fully_qualified=False)
     if fully_qualified:
         old_name = old_attribute_name
     else:
         old_name = ".".join((base_name, old_attribute_name))
     new_name = ".".join((base_name, new_attribute_name))
     prefix = _KIND_MOVED_PREFIX_TPL % (kind, old_name, new_name)
     out_message = _utils.generate_message(
         prefix,
         message=message,
         version=version,
         removal_version=removal_version)
     _utils.deprecation(out_message, stacklevel=stacklevel)
     return f(self, *args, **kwargs)
Пример #20
0
def removed_module(module,
                   replacement=None,
                   message=None,
                   version=None,
                   removal_version=None,
                   stacklevel=3,
                   category=None):
    """Helper to be called inside a module to emit a deprecation warning

    :param str replacment: A location (or information about) of any potential
                           replacement for the removed module (if applicable)
    :param str message: A message to include in the deprecation warning
    :param str version: Specify what version the removed module is present in
    :param str removal_version: What version the module will be removed. If
                                '?' is used this implies an undefined future
                                version
    :param int stacklevel: How many entries deep in the call stack before
                           ignoring
    :param type category: warnings message category (this defaults to
                          ``DeprecationWarning`` when none is provided)
    """
    if inspect.ismodule(module):
        module_name = _get_module_name(module)
    elif isinstance(module, six.string_types):
        module_name = module
    else:
        _qual, type_name = _utils.get_qualified_name(type(module))
        raise TypeError("Unexpected module type '%s' (expected string or"
                        " module type only)" % type_name)
    prefix = "The '%s' module usage is deprecated" % module_name
    if replacement:
        postfix = ", please use %s instead" % replacement
    else:
        postfix = None
    out_message = _utils.generate_message(prefix,
                                          postfix=postfix,
                                          message=message,
                                          version=version,
                                          removal_version=removal_version)
    _utils.deprecation(out_message, stacklevel=stacklevel, category=category)
Пример #21
0
 def wrapper(*args, **kwargs):
     if old_name in kwargs:
         _utils.deprecation(out_message,
                            stacklevel=stacklevel, category=category)
     return f(*args, **kwargs)
Пример #22
0
 def new_init(self, *args, **kwargs):
     _utils.deprecation(out_message, stacklevel=stacklevel,
                        category=category)
     return old_init(self, *args, **kwargs)
Пример #23
0
 def wrapper(f, instance, args, kwargs):
     if old_name in kwargs:
         _utils.deprecation(out_message,
                            stacklevel=stacklevel, category=category)
     return f(*args, **kwargs)
 def wrapper(*args, **kwargs):
     if old_name in kwargs:
         _utils.deprecation(out_message, stacklevel=stacklevel)
     return f(*args, **kwargs)
Пример #25
0
 def wrapper(self, *args, **kwargs):
     _utils.deprecation(out_message,
                        stacklevel=stacklevel,
                        category=category)
     return f(self, *args, **kwargs)
Пример #26
0
 def old_new_func(*args, **kwargs):
     _utils.deprecation(out_message, stacklevel=stacklevel,
                        category=category)
     return new_func(*args, **kwargs)
Пример #27
0
 def wrapper(self, *args, **kwargs):
     _utils.deprecation(out_message, stacklevel=stacklevel,
                        category=category)
     return f(self, *args, **kwargs)
Пример #28
0
 def old_new_func(*args, **kwargs):
     _utils.deprecation(out_message,
                        stacklevel=stacklevel,
                        category=category)
     return new_func(*args, **kwargs)