如何阻止 pyCharm 抱怨下划线字符串? [英] How do I stop pyCharm from complaining about underscore strings?

查看:47
本文介绍了如何阻止 pyCharm 抱怨下划线字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 pyCharm 中编程,制作了一个 wxPython 项目(主要是从 wxGlade 生成的).如果我有一些指定字符串的代码,例如:

I'm programming in pyCharm making a wxPython project (Mostly generated from wxGlade). If I have some code which specifies a string e.g.:

value_label = wx.StaticText(self, wx.ID_ANY, _("Value"))

然后它会抱怨 Unresolved reference '_'.有没有办法只忽略这个未解析的引用?

It then complains about Unresolved reference '_'. Is there any way to ignore only this unresolved reference?

推荐答案

您可以更改未解析引用检查的设置:

You can change the settings of the Unresolved reference inspection:

  • 打开设置...菜单
  • 选择检查页面
  • 搜索未解析的引用并点击检查.在右下角,您应该会看到一个名为 Ignore references 的列表小部件.
  • _ 添加到列表中.
  • Open the Settings... menu
  • Select the Inspections page
  • Search for Unresolved references and click the inspection. On the bottom-right you should see a list widget titled Ignore references.
  • Add _ to the list.

警告:这将忽略项目的所有源文件中未解析的引用_.这通常不是问题,因为您极不可能为函数使用这种名称.如果您收到关于 _NameError,那么您已经知道您忘记调用 gettext.install.

Warning: this will ignore the unresolved reference _ in all source files of the project. This isn't usually a problem because it's highly unlikely that you'd use that kind of name for your functions. If you ever get a NameError about _ then you already know that you forgot to call gettext.install.

或者:

  • 打开有问题的文件并将光标放在 _ 处.
  • Alt+Enter 打开上下文菜单(这可能取决于您选择或配置的快捷方式).
  • 选择忽略未解析的引用module_name._
  • 选择修复所有未解决的引用"问题
  • Open the offending file and place the cursor at an occurence of _.
  • Press Alt+Enter to open the context menu (this may depend on the shortcuts you chose or configured).
  • Select Ignore unresolved reference module_name._
  • Select Fix all 'Unresolved references' problems

我刚刚检查过,可以将其限制为仅一个模块.如果您在 a 模块中使用 _ 则将 a._ 添加到列表 Ignore references 和所有使用a.py 模块中的 _ 将被忽略,而其他模块中的 _ 误用将显示警告.

I just checked and it's possible to limit this to only a module. If you are using _ inside module a then add a._ to the list Ignore references and all usages of _ inside the a.py module will be ignored, while the warnings will be shown for misuses of _ in other modules.

这篇关于如何阻止 pyCharm 抱怨下划线字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆