• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python warnings._warn函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中warnings._warn函数的典型用法代码示例。如果您正苦于以下问题:Python _warn函数的具体用法?Python _warn怎么用?Python _warn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了_warn函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _randbelow

    def _randbelow(self, n, _log=_log, _int=int, _maxwidth=1<<BPF,
                   _Method=_MethodType, _BuiltinMethod=_BuiltinMethodType):
        """Return a random int in the range [0,n)

        Handles the case where n has more bits than returned
        by a single call to the underlying generator.
        """

        try:
            getrandbits = self.getrandbits
        except AttributeError:
            pass
        else:
            # Only call self.getrandbits if the original random() builtin method
            # has not been overridden or if a new getrandbits() was supplied.
            # This assures that the two methods correspond.
            if type(self.random) is _BuiltinMethod or type(getrandbits) is _Method:
                k = _int(1.00001 + _log(n-1, 2.0))   # 2**k > n-1 > 2**(k-2)
                r = getrandbits(k)
                while r >= n:
                    r = getrandbits(k)
                return r
        if n >= _maxwidth:
            _warn("Underlying random() generator does not supply \n"
                "enough bits to choose from a population range this large")
        return _int(self.random() * n)
开发者ID:PySCeS,项目名称:pysces,代码行数:26,代码来源:PyscesRandom.py


示例2: __eq__

 def __eq__(self, other):
     try:
         r = isinstance(self, other)
         _warn("Do not use == to check for event type. That is hacky. Use isinstance instead.")
         return r
     except TypeError:
         return False
开发者ID:BlaXpirit,项目名称:python-csfml,代码行数:7,代码来源:window_events.py


示例3: _randbelow

    def _randbelow(self, n, int=int, maxsize=1<<BPF, type=type,
                   Method=_MethodType, BuiltinMethod=_BuiltinMethodType):
        "Return a random int in the range [0,n).  Raises ValueError if n==0."

        getrandbits = self.getrandbits
        # Only call self.getrandbits if the original random() builtin method
        # has not been overridden or if a new getrandbits() was supplied.
        if type(self.random) is BuiltinMethod or type(getrandbits) is Method:
            k = n.bit_length()  # don't use (n-1) here because n can be 1
            r = getrandbits(k)          # 0 <= r < 2**k
            while r >= n:
                r = getrandbits(k)
            return r
        # There's an overriden random() method but no new getrandbits() method,
        # so we can only use random() from here.
        random = self.random
        if n >= maxsize:
            _warn("Underlying random() generator does not supply \n"
                "enough bits to choose from a population range this large.\n"
                "To remove the range limitation, add a getrandbits() method.")
            return int(random() * n)
        rem = maxsize % n
        limit = (maxsize - rem) / maxsize   # int(limit * maxsize) % n == 0
        r = random()
        while r >= limit:
            r = random()
        return int(r*maxsize) % n
开发者ID:AndyPanda95,项目名称:python-for-android,代码行数:27,代码来源:random.py


示例4: update

 def update(self, *arg, **kw):
     if arg:
         if len(arg) > 1:
             raise TypeError("at most one non-keyword argument permitted")
         arg = arg[0]
         if hasattr(arg, "keys"):
             if not self.is_ordered(arg):
                 _warn(_WRNnoOrderArg, RuntimeWarning, stacklevel=2)
             super(StableDict, self).update(arg)
             ksl = self.__ksl
             for k in arg.keys():
                 if k not in ksl:
                     ksl.append(k)
             self.__ksl = ksl
         else: # Must be a sequence of 2-tuples.
              for pair in arg:
                 if len(pair) != 2:
                     raise ValueError("not a 2-tuple", pair)
                 self.__setitem__(pair[0], pair[1])
     if kw:
         # There have been additionial keyword arguments.
         # Since Python passes them in an (unordered) dict
         # we cannot possibly preserve their order (without
         # inspecting the source or byte code of the call).
         if len(kw) > 1:
             _warn(_WRNnoOrderKW, RuntimeWarning, stacklevel=2)
         super(StableDict, self).update(kw)
         ksl = self.__ksl
         for k in kw.iterkeys():
             if k not in ksl:
                 ksl.append(k)
         self.__ksl = ksl
开发者ID:vgurev,项目名称:freesurfer,代码行数:32,代码来源:datastruct_utils.py


示例5: _check_dtype_mistake

def _check_dtype_mistake(dtype):
    """
    It's a very common mistake (at least for me) to pass-in a float64 when I
    really want to pass in a `floatX`, and it would go unnoticed and slow-down
    the computations a lot if I wouldn't check it here.
    """
    if _np.issubdtype(dtype, _np.floating) and dtype != df.floatX:
        _warn("Input array of floating-point dtype {} != df.floatX detected. Is this really what you want?".format(dtype))
开发者ID:yobibyte,项目名称:DeepFried2,代码行数:8,代码来源:utils.py


示例6: evaluate

    def evaluate(self):
        df.Module.evaluate(self)
        self.Winf.set_value(self.W.get_value() / _np.sqrt(self.buf_var.get_value() + self.eps))
        self.binf.set_value(self.b.get_value() - self.Winf.get_value() * self.buf_mean.get_value())

        # This check saved me from WTF'ing countless times!
        if self.buf_count.get_value() == 0:
            _warn("You're switching a BN-net to eval mode without having collected any statistics, that can't go well!")
开发者ID:yobibyte,项目名称:DeepFried2,代码行数:8,代码来源:BatchNormalization.py


示例7: __init__

 def __init__(self, depth=0, stencil=0, antialiasing=0, major=2, minor=0, **kwargs):
     self._sfContextSettings = _ffi.new('sfContextSettings*')
     if antialiasing and not depth:
         _warn("Antialiasing may not work if depth is not set")
     self.depth_bits = depth
     self.stencil_bits = stencil
     self.antialiasing_level = antialiasing
     self.major_version = major
     self.minor_version = minor
     if kwargs: self._set(**kwargs)
开发者ID:BlaXpirit,项目名称:python-csfml,代码行数:10,代码来源:window.py


示例8: discontinued

def discontinued(_type, name, version, stack_level=2):
    """convenience func to warn about discontinued attributes
    Arguments:
        - _type should be one of class, method, function, argument
        - name: the attributes name
        - version: the version by which support for the old name will be
          discontinued
        - stack_level: as per warnings.warn"""
    msg = "%s %s is discontinued, support will be stopped in version %s" % (_type, name, version)
    _warn(msg, DeprecationWarning, stack_level)
开发者ID:pombredanne,项目名称:pycogent-1,代码行数:10,代码来源:warning.py


示例9: deprecated

def deprecated(_type, old, new, version, stack_level=2):
    """a convenience function for deprecating classes, functions, arguments.
    
    Arguments:
        - _type should be one of class, method, function, argument
        - old, new: the old and new names
        - version: the version by which support for the old name will be
          discontinued
        - stack_level: as per warnings.warn"""
    msg = "use %s %s instead of %s, support discontinued in version %s" % (_type, new, old, version)
    _warn(msg, DeprecationWarning, stack_level)
开发者ID:pombredanne,项目名称:pycogent-1,代码行数:11,代码来源:warning.py


示例10: pendingDeprecation

def pendingDeprecation(new_func):
    """
    Raise `PendingDeprecationWarning` and display a message.

    Uses inspect.stack() to determine the name of the item that this
    is called from.

    :param new_func: The name of the function that should be used instead.
    :type new_func: string.
    """
    warn_txt = "`{}` is pending deprecation. Please use `{}` instead."
    _warn(warn_txt.format(inspect.stack()[1][3], new_func),
          PlotPendingDeprecation)
开发者ID:GadgetSteve,项目名称:Phoenix,代码行数:13,代码来源:utils.py


示例11: deprecated

def deprecated(_type, old, new, version, stack_level=2):
    """a convenience function for deprecating classes, functions, arguments.
    
    Arguments:
        - _type should be one of class, method, function, argument
        - old, new: the old and new names
        - version: the version by which support for the old name will be
          discontinued
        - stack_level: as per warnings.warn"""
    msg = "use %s %s instead of %s, support discontinued in version %s" % \
        (_type, new, old, version)

    # DeprecationWarnings are ignored by default in python 2.7, so temporarily
    # force them to be handled.
    with catch_warnings():
        simplefilter("always")
        _warn(msg, DeprecationWarning, stack_level)
开发者ID:miklou,项目名称:pycogent,代码行数:17,代码来源:warning.py


示例12: _randbelow

 def _randbelow(self, n, int=int, maxsize=1 << BPF, type=type, Method=_MethodType, BuiltinMethod=_BuiltinMethodType):
     getrandbits = self.getrandbits
     if type(self.random) is BuiltinMethod or type(getrandbits) is Method:
         k = n.bit_length()
         r = getrandbits(k)
         while r >= n:
             r = getrandbits(k)
         return r
     random = self.random
     if n >= maxsize:
         _warn('Underlying random() generator does not supply \nenough bits to choose from a population range this large.\nTo remove the range limitation, add a getrandbits() method.')
         return int(random()*n)
     rem = maxsize % n
     limit = (maxsize - rem)/maxsize
     r = random()
     while r >= limit:
         r = random()
     return int(r*maxsize) % n
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:18,代码来源:random.py


示例13: _randbelow_without_getrandbits

    def _randbelow_without_getrandbits(self, n, int=int, maxsize=1<<BPF):
        """Return a random int in the range [0,n).  Raises ValueError if n==0.

        The implementation does not use getrandbits, but only random.
        """

        random = self.random
        if n >= maxsize:
            _warn("Underlying random() generator does not supply \n"
                "enough bits to choose from a population range this large.\n"
                "To remove the range limitation, add a getrandbits() method.")
            return int(random() * n)
        if n == 0:
            raise ValueError("Boundary cannot be zero")
        rem = maxsize % n
        limit = (maxsize - rem) / maxsize   # int(limit * maxsize) % n == 0
        r = random()
        while r >= limit:
            r = random()
        return int(r*maxsize) % n
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:20,代码来源:random.py


示例14: __init__

    def __init__(self, f=None, g=None, A=None, B=None, gamma=1.0, alpha=None, epsilon=None, *args, **kwargs):
        super(ForwardBackward, self).__init__(*args, **kwargs)

        if (A is None) == (f is None):
            raise TypeError("must specify either A or f, but not both")
        if A is None:
            A = f.gradient
        if (B is None) == (g is None):
            raise TypeError("must specify either B or g, but not both")
        if B is None:
            B = g.gradient

        if A.shape[0] is None:
            assert B.shape[0] is not None
            self.x = _np.zeros(B.shape[0])
        elif B.shape[0] is None:
            assert A.shape[0] is not None
            self.x = _np.zeros(A.shape[0])
        else:
            assert A.shape[0] == B.shape[0]
            self.x = _np.zeros(A.shape[0])

        if not 0 < gamma < 2:
            _warn("convergence is only guaranteed for 0 < gamma < 2")

        if alpha is None:
            if epsilon is not None:
                if not 0 < epsilon < (9.0 - 4 * gamma) / (2.0 * gamma):
                    _warn("convergence is only guaranteed for 0 < epsilon < (9.0 - 4 * gamma) / (2.0 * gamma)")
                alpha = 1 + (_np.sqrt(9.0 - 4 * gamma - 2 * epsilon * gamma) - 3) / gamma
            else:
                alpha = 0
        else:
            if not 0 <= alpha < 1:
                _warn("convergence is only guaranteed for 0 <= alpha < 1")
            if epsilon is not None:
                _warn("ignoring epsilon since alpha is given")

        self._A = A
        self._B = B
        self._tau = gamma / B.lipschitz
        self._alpha = alpha

        if self._alpha:
            self._last_x = self.x
开发者ID:haoyuanchi,项目名称:convexopt,代码行数:45,代码来源:forwardbackward.py


示例15: __new__

    def __new__(cls, name, bases, dct):
        newcls = super(cls, CallbackMeta).__new__(cls, name, bases, dct)
        try:
            argspec = _getargspec(dct["__init__"])
        except (KeyError, TypeError):
            pass
        else:
            args = argspec.args[1:]
            if argspec.varargs:
                _warn("varargs in %r" % cls)
            if argspec.keywords:
                _warn("keywords in %r" % cls)

            for arg in args:
                if arg in cls.registry:
                    _warn("ambiguous constructor argument %r in %r"
                                  % (arg, cls))
                else:
                    cls.registry[arg] = newcls
        return newcls
开发者ID:haoyuanchi,项目名称:convexopt,代码行数:20,代码来源:util.py


示例16: find_lines

def find_lines(code, strs):
    _warn("The trace.find_lines() function is deprecated",
         DeprecationWarning, 2)
    return _find_lines(code, strs)
开发者ID:Badcreature,项目名称:sagcg,代码行数:4,代码来源:trace.py


示例17: fullmodname

def fullmodname(path):
    _warn("The trace.fullmodname() function is deprecated",
         DeprecationWarning, 2)
    return _fullmodname(path)
开发者ID:Badcreature,项目名称:sagcg,代码行数:4,代码来源:trace.py


示例18: __init__

 def __init__(self, modules=None, dirs=None):
     _warn("The class trace.Ignore is deprecated",
          DeprecationWarning, 2)
     _Ignore.__init__(self, modules, dirs)
开发者ID:Badcreature,项目名称:sagcg,代码行数:4,代码来源:trace.py


示例19: usage

def usage(outfile):
    _warn("The trace.usage() function is deprecated",
         DeprecationWarning, 2)
    _usage(outfile)
开发者ID:Badcreature,项目名称:sagcg,代码行数:4,代码来源:trace.py


示例20: DBusGMainLoop

# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

"""Deprecated module which sets the default GLib main context as the mainloop
implementation within D-Bus, as a side-effect of being imported!

This API is highly non-obvious, so instead of importing this module,
new programs which don't need pre-0.80 compatibility should use this
equivalent code::

    from dbus.mainloop.glib import DBusGMainLoop
    DBusGMainLoop(set_as_default=True)
"""
__docformat__ = 'restructuredtext'

from dbus.mainloop.glib import DBusGMainLoop, threads_init
from warnings import warn as _warn

init_threads = threads_init

DBusGMainLoop(set_as_default=True)

_warn(DeprecationWarning("""\
Importing dbus.glib to use the GLib main loop with dbus-python is deprecated.
Instead, use this sequence:

    from dbus.mainloop.glib import DBusGMainLoop

    DBusGMainLoop(set_as_default=True)
"""), DeprecationWarning, stacklevel=2)
开发者ID:ArslanRafique,项目名称:dist-packages,代码行数:30,代码来源:glib.py



注:本文中的warnings._warn函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python warnings.append函数代码示例发布时间:2022-05-26
下一篇:
Python warning_tests.inner函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap