當前位置: 首頁>>代碼示例>>Python>>正文


Python warnings.warn_explicit方法代碼示例

本文整理匯總了Python中warnings.warn_explicit方法的典型用法代碼示例。如果您正苦於以下問題:Python warnings.warn_explicit方法的具體用法?Python warnings.warn_explicit怎麽用?Python warnings.warn_explicit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在warnings的用法示例。


在下文中一共展示了warnings.warn_explicit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: deprecated

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def deprecated(func):
    """This is a decorator which can be used to mark functions
    as deprecated. It will result in a warning being emitted
    when the function is used.
    """

    @functools.wraps(func)
    def new_func(*args, **kwargs):
        warnings.simplefilter("always", DeprecationWarning)  # turn off filter
        warnings.warn_explicit(
            "Call to deprecated function {}.".format(func.__name__),
            category=DeprecationWarning,
            filename=func.__code__.co_filename,
            lineno=func.__code__.co_firstlineno + 1,
        )
        warnings.simplefilter("default", DeprecationWarning)  # reset filter
        logger.warn(
            "%s - DeprecationWarning: Call to deprecated function %s. %s:%s"
            % (datetime.datetime.now(), func.__name__, func.__code__.co_filename, func.__code__.co_firstlineno + 1)
        )
        return func(*args, **kwargs)

    return new_func 
開發者ID:archesproject,項目名稱:arches,代碼行數:25,代碼來源:decorators.py

示例2: __call__

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def __call__(self, func):
        msg = "Call to deprecated function {}".format(func.__name__)
        if self.use_instead:
            msg += '; use ' + self.use_instead + ' instead'

        def wrapper(*args, **kwargs):
            fingerprint = (func.__name__, func.__code__.co_filename, func.__code__.co_firstlineno)
            if fingerprint not in self.seen:
                warnings.warn_explicit(
                    msg,
                    category=DeprecationWarning,
                    filename=func.__code__.co_filename,
                    lineno=func.__code__.co_firstlineno + 1)
            self.seen.update([fingerprint])
            return func(*args, **kwargs)

        wrapper.__doc__ = "Deprecated"
        if self.use_instead:
            wrapper.__doc__ += '; use ' + self.use_instead + ' instead'
        return wrapper 
開發者ID:biocommons,項目名稱:hgvs,代碼行數:22,代碼來源:deprecated.py

示例3: handle_old_config

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def handle_old_config(self, filename):
        warnings.warn_explicit(self.old_warning, ConfigDeprecationWarning,
                               filename, 0)
        options = self.get_section('options')
        if not self.has_section('general'):
            self.add_section('general')
        for key, value in list(options.items()):
            if key in self.old_settings:
                section, setting = self.old_settings[key]
                if not self.has_section(section):
                    self.add_section(section)
            else:
                section = 'general'
                setting = key
            if not self.has_option(section, setting):
                self.set(section, setting, value)
        self.remove_section('options') 
開發者ID:skarlekar,項目名稱:faces,代碼行數:19,代碼來源:frontend.py

示例4: handle_old_config

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def handle_old_config(self, filename):
        warnings.warn_explicit(self.old_warning, ConfigDeprecationWarning,
                               filename, 0)
        options = self.get_section('options')
        if not self.has_section('general'):
            self.add_section('general')
        for key, value in options.items():
            if key in self.old_settings:
                section, setting = self.old_settings[key]
                if not self.has_section(section):
                    self.add_section(section)
            else:
                section = 'general'
                setting = key
            if not self.has_option(section, setting):
                self.set(section, setting, value)
        self.remove_section('options') 
開發者ID:skarlekar,項目名稱:faces,代碼行數:19,代碼來源:frontend.py

示例5: _unjelly_instance

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def _unjelly_instance(self, rest):
        """
        (internal) Unjelly an instance.

        Called to handle the deprecated I{instance} token.

        @param rest: The s-expression representing the instance.

        @return: The unjellied instance.
        """
        warnings.warn_explicit(
            "Unjelly support for the instance atom is deprecated since "
            "Twisted 15.0.0.  Upgrade peer for modern instance support.",
            category=DeprecationWarning, filename="", lineno=0)

        clz = self.unjelly(rest[0])
        if not _PY3 and type(clz) is not _OldStyleClass:
            raise InsecureJelly("Legacy 'instance' found with new-style class")
        return self._genericUnjelly(clz, rest[1]) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:21,代碼來源:jelly.py

示例6: show_param_warnings

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def show_param_warnings(app, exception):
    import inspect

    for (fname, fun), params in param_warnings.items():
        _, line = inspect.getsourcelines(fun)
        file_name = inspect.getsourcefile(fun)
        params_str = '\n'.join(f'\t{n}: {t}' for n, t in params)
        warnings.warn_explicit(
            f'\nParameters in `{fname}` have types in docstring.\n'
            f'Replace them with type annotations.\n{params_str}',
            UserWarning,
            file_name,
            line,
        )
    if param_warnings:
        raise RuntimeError('Encountered text parameter type. Use annotations.') 
開發者ID:theislab,項目名稱:scanpy,代碼行數:18,代碼來源:param_police.py

示例7: deprecated

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def deprecated(version, version_removed):
    '''This is a decorator which can be used to mark functions
    as deprecated.

    It will result in a warning being emitted when the function is used.'''

    def __wrapper(func, *args, **kwargs):
        '''Warn the user, and then proceed.'''
        code = six.get_function_code(func)
        warnings.warn_explicit(
            "{:s}.{:s}\n\tDeprecated as of JAMS version {:s}."
            "\n\tIt will be removed in JAMS version {:s}."
            .format(func.__module__, func.__name__,
                    version, version_removed),
            category=DeprecationWarning,
            filename=code.co_filename,
            lineno=code.co_firstlineno + 1
        )
        return func(*args, **kwargs)

    return decorator(__wrapper) 
開發者ID:marl,項目名稱:jams,代碼行數:23,代碼來源:core.py

示例8: handle_error

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def handle_error(self, wrapper, exception, traceback_):
        if hasattr(wrapper, "gccxml_definition"):
            definition = wrapper.gccxml_definition
        elif hasattr(wrapper, "main_wrapper"):
            try:
                definition = wrapper.main_wrapper.gccxml_definition
            except AttributeError:
                definition = None
        else:
            definition = None

        if definition is None:
            print("exception %r in wrapper %s" % (exception, wrapper), file=sys.stderr)
        else:
            warnings.warn_explicit("exception %r in wrapper for %s"
                                   % (exception, definition),
                                   WrapperWarning, definition.location.file_name,
                                   definition.location.line)
        return True 
開發者ID:KTH,項目名稱:royal-chaos,代碼行數:21,代碼來源:gccxmlparser.py

示例9: _get_calldef_exceptions

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def _get_calldef_exceptions(self, calldef):
        retval = []
        for decl in calldef.exceptions:
            traits = ctypeparser.TypeTraits(normalize_name(decl.partial_decl_string))
            if traits.type_is_reference:
                name = str(traits.target)
            else:
                name = str(traits.ctype)
            exc = self.type_registry.root_module.get(name, None)
            if isinstance(exc, CppException):
                retval.append(exc)
            else:
                warnings.warn_explicit("Thrown exception '%s' was not previously detected as an exception class."
                                       " PyBindGen bug?"
                                       % (normalize_name(decl.partial_decl_string)),
                                       WrapperWarning, calldef.location.file_name, calldef.location.line)
        return retval 
開發者ID:KTH,項目名稱:royal-chaos,代碼行數:19,代碼來源:gccxmlparser.py

示例10: test_once

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def test_once(self):
        with original_warnings.catch_warnings(record=True,
                module=self.module) as w:
            self.module.resetwarnings()
            self.module.filterwarnings("once", category=UserWarning)
            message = UserWarning("FilterTests.test_once")
            self.module.warn_explicit(message, UserWarning, "__init__.py",
                                    42)
            self.assertEqual(w[-1].message, message)
            del w[:]
            self.module.warn_explicit(message, UserWarning, "__init__.py",
                                    13)
            self.assertEqual(len(w), 0)
            self.module.warn_explicit(message, UserWarning, "test_warnings2.py",
                                    42)
            self.assertEqual(len(w), 0) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:__init__.py

示例11: deprecated

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def deprecated(func):
  '''This is a decorator which can be used to mark functions
  as deprecated. It will result in a warning being emitted
  when the function is used.'''

  @functools.wraps(func)
  def new_func(*args, **kwargs):
    warnings.warn_explicit(
      "Call to deprecated function {}.".format(func.__name__),
      category=DeprecationWarning,
      filename=func.func_code.co_filename,
      lineno=func.func_code.co_firstlineno + 1
    )
    return func(*args, **kwargs)

  return new_func 
開發者ID:yselivonchyk,項目名稱:TensorFlow_DCIGN,代碼行數:18,代碼來源:utils.py

示例12: test_once

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def test_once(self):
        with original_warnings.catch_warnings(record=True,
                module=self.module) as w:
            self.module.resetwarnings()
            self.module.filterwarnings("once", category=UserWarning)
            message = UserWarning("FilterTests.test_once")
            self.module.warn_explicit(message, UserWarning, "test_warnings.py",
                                    42)
            self.assertEqual(w[-1].message, message)
            del w[:]
            self.module.warn_explicit(message, UserWarning, "test_warnings.py",
                                    13)
            self.assertEqual(len(w), 0)
            self.module.warn_explicit(message, UserWarning, "test_warnings2.py",
                                    42)
            self.assertEqual(len(w), 0) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:18,代碼來源:test_warnings.py

示例13: deprecated

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def deprecated(alternative=None):
    """This is a decorator which can be used to mark functions
    as deprecated. It will result in a warning being emitted
    when the function is used."""

    def real_decorator(func):
        @functools.wraps(func)
        def new_func(*args, **kwargs):
            msg = "Call to deprecated function {0}.".format(func.__name__)
            if alternative:
                msg += " Use {0} instead".format(alternative)
            warnings.warn_explicit(
                msg,
                category=DeprecationWarning,
                filename=compat.get_function_code(func).co_filename,
                lineno=compat.get_function_code(func).co_firstlineno + 1,
            )
            return func(*args, **kwargs)

        return new_func

    return real_decorator 
開發者ID:elastic,項目名稱:apm-agent-python,代碼行數:24,代碼來源:deprecation.py

示例14: warn

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def warn(msg, stacklevel=3):
    """Issue a warning.

    If msg is a string, :class:`.exc.SAWarning` is used as
    the category.

    .. note::

       This function is swapped out when the test suite
       runs, with a compatible version that uses
       warnings.warn_explicit, so that the warnings registry can
       be controlled.

    """
    if isinstance(msg, compat.string_types):
        warnings.warn(msg, exc.SAWarning, stacklevel=stacklevel)
    else:
        warnings.warn(msg, stacklevel=stacklevel) 
開發者ID:gltn,項目名稱:stdm,代碼行數:20,代碼來源:langhelpers.py

示例15: deprecated

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warn_explicit [as 別名]
def deprecated(func):
    '''This is a decorator which can be used to mark functions
    as deprecated. It will result in a warning being emitted
    when the function is used.'''

    @functools.wraps(func)
    def new_func(*args, **kwargs):
        warnings.warn_explicit(
            "Call to deprecated function {}.".format(func.__name__),
            category=DeprecationWarning,
            filename=func.func_code.co_filename,
            lineno=func.func_code.co_firstlineno + 1
        )
        return func(*args, **kwargs)

    return new_func 
開發者ID:KanColleTool,項目名稱:kcsrv,代碼行數:18,代碼來源:util.py


注:本文中的warnings.warn_explicit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。