如何告诉 Pychecker 忽略导入的库?

发布于 2024-09-19 16:40:21 字数 338 浏览 4 评论 0原文

我导入到 python 项目中的模块之一在 Pychecker 下触发了许多警告。修复这个外部模块并不是真正的选择,所以我想告诉 Pychecker 忽略它。

有谁知道该怎么做?我确信这是可能的,而且可能非常简单,但在谷歌搜索了一段时间后,我没有找到任何文档或示例。

谢谢, Sam

编辑:不幸的是,我无法用“pychecker”标记此标签,因为该标签尚不存在,而且我的代表太低,无法创建。

编辑 2 额外问题:pychecker 是否会检查被忽略的模块,并且不打印它找到的任何内容?或者您是否通过忽略某些模块来获得一些加速?

One of the modules I import into my python project triggers lots of warnings under Pychecker. Fixing up this external module isn't really an option, so I want to tell Pychecker to ignore it.

Does anyone know how to do this? I'm sure it's possible, and probably quite simple, but after trawling Google for a while I've not found any documentation or examples.

Thanks,
Sam

Edit: I can't tag this with 'pychecker' unfortunately as that tag doesn't exist yet and my rep is too low to create.

Edit 2 Bonus extra question: does pychecker check ignored modules anyway, and just not print anything it finds? or do you get some speedup by ignoring some modules?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

送舟行 2024-09-26 16:40:21

根据 文档

如果你想抑制警告
模块/函数/类/方法,你可以
定义一个抑制字典
.pycheckrc。键的示例有:
'模块', '模块.函数',
'模块.类', '模块.类.方法',
等等等等

IOW,在您的 .pycheckrc 中,如果这个麻烦的模块名为 foobar,您将拥有

suppressions = {'foobar': '...'}

... 表示的所有您想要的抑制选项。使用 pychecker -h 获取所有选项的列表;我认为 'limit=0' 会满足您的要求(该模块最多显示 0 个警告,即无;-),但您可能希望更有选择性(毕竟,您只需在 .pycheckrc 中一次性编写此代码,而不是在调用 pychecker 的每个位置上编写...这是方便的pycheckrc 方法!)。

Per the docs,

If you want to suppress warnings on a
module/function/class/method, you can
define a suppressions dictionary in
.pycheckrc. Examples of keys are:
'module', 'module.function',
'module.class', 'module.class.method',
etc.etc.

IOW, in your .pycheckrc, if the troublesome module is named foobar, you'll have

suppressions = {'foobar': '...'}

where the ... means, all the suppress options you want. Use pychecker -h to get a list of all the options; I think 'limit=0' will do what you're asking for (show a max of 0 warnings for that module, i.e., none;-), but you may want to be a bit more selective (after all you only have to write this once and for all in .pycheckrc, not on every spot from which you're calling pychecker... which is the convenience of the pycheckrc approach!).

会发光的星星闪亮亮i 2024-09-26 16:40:21

我找到了另一个选项 - 您可以使用 -b 标志将其列入黑名单。例如,

python pychecker.py -b list,of,modules,to,ignore

我不确定,但我认为这无论如何都会检查导入的模块,但只是不打印警告。使用 -b 标志肯定不会比不使用 -b 标志更快 - 尽管至少警告消失了:-)

I've found another option - you can blacklist using the -b flag. Eg

python pychecker.py -b list,of,modules,to,ignore

I'm not sure, but I think this checks the imported modules anyway, but just doesn't print the warnings. It certainly doesn't seem any faster with the -b flag than without - though at least the warnings are gone :-)

仲春光 2024-09-26 16:40:21

关于额外的问题:

  • pychecker 总是导入您传递给它的文件,这会导致它导入所有导入的文件。这就像Python一样。这是 pychecker 中的第一遍。
  • 然后 pychecker 将实际检查加载的模块,反汇编代码,并运行所有操作码。这是第二次通过。
  • 在这两种情况下,它都会跟踪甚至由被忽略的模块生成的所有警告。然后它会在显示警告之前过滤掉这些警告。

我正在考虑是否值得将 pychecker 更改为根本不查看黑名单模块,或者使其可以仅反汇编一个文件(例如,用于在编辑器中集成)。

On the bonus extra question:

  • pychecker always imports the files you pass it, which causes it to import whatever those import. This is just like Python. This is a first pass in pychecker.
  • Then pychecker will actually go through the loaded modules, disassemble the code, and run through all the opcodes. This is a second pass.
  • In both cases, it tracks all warnings generated even by ignored modules. Then it filters out those warnings before showing them.

I am considering if it is worth it to change pychecker to not even look at blacklisted modules at all, or make it possible to only disassemble the one file (for integration in an editor for example).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文