简体   繁体   English

禁止来自Cython的警告

[英]Suppress warnings from Cython

I cythonize *.pyx files manually using 我手动使用*.pyx文件*.pyx

cython -3 -Wextra mymodule.pyx

I use the -Wextra option to generate additional warnings, useful for cleaning up redundant code pieces. 我使用-Wextra选项生成其他警告,对于清除冗余代码段很有用。 However, many warnings of the form 但是,许多警告形式

warning: mymodule.pyx:123:45: local variable 'x' might be referenced before assignment

are printed, which I do not care for. 被打印,我不在乎。 I understand why it is not obvious from the perspective of the compiler, but under no circumstance is it ever possible for x to not be assigned before referencing, in my particular situation. 我理解为什么从编译器的角度来看这并不明显,但是在我的特定情况下,在任何情况下都不可能在引用之前不分配x

I would therefore like to keep using -Wextra but filter out this type of warning, similar to the -Wno option of gcc. 因此,我想继续使用-Wextra但过滤掉此类警告,类似于gcc的-Wno选项。 I have however not been able to track down such a feature. 但是,我无法找到这样的功能。

Warnings in cython are controlled via compiler directives; cython中的警告是通过编译器指令控制的; they only seem to be partially documented currently, but you can see the full list in the Cython source . 它们目前似乎只被部分记录 ,但是您可以在Cython 源中查看完整列表。

In this case you want warn.maybe_uninitialized , passed to the --directive option. 在这种情况下,您需要将warn.maybe_uninitialized传递给--directive选项。

$ cython test.pyx -Wextra
warning: test.pyx:7:12: local variable 'x' might be referenced before assignment

$ cython test.pyx -Wextra --directive warn.maybe_uninitialized=False
# no warning

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM