标签: suppress-warnings

如何在加载文件时禁用重新定义常量的警告

有没有办法warning: already initialized constant在加载特定文件时禁用?

ruby warnings constants suppress-warnings

30
推荐指数
4
解决办法
1万
查看次数

在NumPy中忽略除以0警告

我有统计问题的功能:

import numpy as np
from scipy.special import gamma as Gamma

def Foo(xdata):
    ...
    return x1 * (
                 ( #R is a numpy vector
                  ( ((R - x2)/beta) ** (x3 -1) ) * 
                  ( np.exp( - ((R - x2) / x4) ) ) /
                  ( x4 * Gamma(x3))
                 ).real
                )
Run Code Online (Sandbox Code Playgroud)

有时我会从shell获得以下警告:

RuntimeWarning: divide by zero encountered in...
Run Code Online (Sandbox Code Playgroud)

我使用numpy isinf函数来纠正其他文件中函数的结果,所以我不需要这个警告.

有没有办法忽略这条消息?换句话说,我不希望shell打印此消息.

我不想禁用所有python警告,只是这个.

python numpy divide-by-zero suppress-warnings

29
推荐指数
1
解决办法
2万
查看次数

铸造到'void'真的有什么作用?

经常使用的语句(void)x;允许禁止有关未使用变量的警告x.但是如果我尝试编译以下内容,我会得到一些我不太了解的结果:

int main()
{
    int x;
    (short)x;
    (void)x;
    (int)x;
}
Run Code Online (Sandbox Code Playgroud)

用g ++编译它,我得到以下警告:

$ g++ test.cpp -Wall -Wextra -o test
test.cpp: In function ‘int main()’:
test.cpp:4:13: warning: statement has no effect [-Wunused-value]
     (short)x;
             ^
test.cpp:6:11: warning: statement has no effect [-Wunused-value]
     (int)x;
           ^
Run Code Online (Sandbox Code Playgroud)

因此,我得出结论,转换为void与任何其他类型的转换非常不同,是目标类型相同decltype(x)或不同的东西.我猜测可能的解释是:

  • 这只是一个惯例,(void)x;但其他演员不会抑制警告.所有陈述同样没有任何效果.
  • 这种差异在某种程度上与事实有关,而事实void x;并非如此short x;.

哪一项更正确?如果没有,那么如何解释编译器警告的差异?

c++ casting void compiler-warnings suppress-warnings

29
推荐指数
3
解决办法
1万
查看次数

我可以让PyCharm在一条线上抑制特定的警告吗?

PyCharm在代码样式,约定和逻辑陷阱上提供了一些有用的警告.如果我尝试提交带有警告(或错误)的代码,它也会提供通知.

有时我会有意识地忽略特定代码行的这些警告(出于各种原因,通常要考虑第三方库的实现细节).我想要压制警告,但只是为了那条线(如果警告出现在我不是故意的另一条线上,我想知道它!)

我怎么能在PyCharm中做到这一点?(遵循通用Python约定非常可取.)

python compiler-warnings suppress-warnings pycharm

28
推荐指数
3
解决办法
1万
查看次数

在Xcode中禁用特定行中的特定警告

我正在针对Base 4.0 SDK编写iPhone应用程序,但我的目标是OS 3.1.3,因此OS 3用户可以使用该应用程序.

我打电话:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
Run Code Online (Sandbox Code Playgroud)

在iOS 4.0中已弃用.我知道这一点,如果我们在iOS 4.0或更高版本下运行,我们已采取措施调用较新的"withAnimation"版本.

但是,我收到一条警告,我正在调用一个已弃用的SDK.

我想在这个特定的地方禁用此特定警告.我想要所有其他警告(包括其他位置的相同弃用警告)

这可以在Xcode中实现吗?

iphone xcode warnings suppress-warnings

27
推荐指数
3
解决办法
1万
查看次数

如何禁止特定函数的Java编译器警告

我们总是被教导确保我们在switch语句中使用break来避免掉头.

Java编译器警告这些情况,以帮助我们不要做出微不足道的(但是很严重的)错误.

但是,我使用了case-fall-through作为一个功能(我们不必在这里进入它,但它提供了一个非常优雅的解决方案).

然而,编译器会发出大量警告,这些警告可能会掩盖我需要了解的警告.我知道如何更改编译器以忽略所有直通警告,但我想在逐个方法的基础上实现这一点,以避免错过我不打算发生跌倒的地方.

有任何想法吗?

java compiler-construction warnings compiler-warnings suppress-warnings

24
推荐指数
1
解决办法
5万
查看次数

如何在GCC中消除外部lib /第三方警告

在我正在进行的软件项目中,我们使用了某些第三方库,遗憾的是,这些库产生了恼人的gcc警告.我们正在努力清除所有警告代码,并希望在GCC中启用treat-warnings-as-errors(-Werror)标志.有没有办法让这些我们无法修复的第三方生成的警告消失?

c++ gcc include suppress-warnings gcc-warning

24
推荐指数
3
解决办法
8039
查看次数

如何抑制字段或局部变量的FindBugs警告

我想抑制特定字段或局部变量的FindBugs警告.FindBugs文档指出Target的edu.umd.cs.findbugs.annotations.SuppressWarning注释[1]可以是Type,Field,Method,Parameter,Constructor,Package.但是,只有当我注释警告被抑制的方法时,它才能对我进行注释.

注释整个方法似乎对我来说很广泛.有没有办法抑制特定字段的警告?还有另一个相关问题[2],但没有答案.

[1] http://findbugs.sourceforge.net/manual/annotations.html

[2] 在Eclipse中抑制FindBugs警告

演示代码:

public class SyncOnBoxed
{
    static int counter = 0;
    // The following SuppressWarnings does NOT prevent the FindBugs warning
    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE")
    final static Long expiringLock = new Long(System.currentTimeMillis() + 10);

    public static void main(String[] args) {
        while (increment(expiringLock)) {
            System.out.println(counter);
        }
    }

    // The following SuppressWarnings prevents the FindBugs warning
    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE")
    protected static boolean increment(Long expiringLock)
    {
        synchronized (expiringLock) { // <<< FindBugs warning is here: Synchronization on Long in SyncOnBoxed.increment()
            counter++;
        }
        return …
Run Code Online (Sandbox Code Playgroud)

java findbugs suppress-warnings

24
推荐指数
1
解决办法
3万
查看次数

抑制AndroidManifest.xml与minSdkVersion相关的警告

正如http://developer.android.com/guide/practices/screens_support.html所述,出于兼容性原因,我的AndroidManifest.xml包含以下内容:

<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4"/>
Run Code Online (Sandbox Code Playgroud)

这会在eclipse中生成警告:

属性minSdkVersion(3)低于项目目标API级别(4)

有没有办法压制这个警告或以任何其他方式摆脱它?这真的很烦人.

android suppress-warnings android-manifest

23
推荐指数
1
解决办法
4500
查看次数

如何获得warnings.warn发出警告而不忽略该行?

我正在尝试DeprecationWarning使用基于文档中显示的示例的代码段来引发一个.http://docs.python.org/2/library/warnings.html#warnings.warn

官方

def deprecation(message):
    warnings.warn(message, DeprecationWarning, stacklevel=2)
Run Code Online (Sandbox Code Playgroud)

import warnings
warnings.warn("This is a warnings.", DeprecationWarning, stacklevel=2) is None  # returns True
Run Code Online (Sandbox Code Playgroud)

我已经尝试删除stacklevel参数,将其设置为负数,0,2和20000.警告总是被静默吞下.它不会发出警告或引发异常.它只是忽略了线和返回None.文档没有提到忽略的标准.发送消息,使warnings.warn正确发出一个Userwarning.

可能导致这种情况的原因以及如何警告实际发出警告?

python warnings suppress-warnings python-2.7

23
推荐指数
2
解决办法
1万
查看次数