PyCharm Says readline Import Not Being Used

我与影子孤独终老i 提交于 2020-05-15 08:12:15

问题


I had this code:

while True:
    cmd = input('> ')
    if cmd == 'exit':
        break

But I wanted to implement advanced text input features like command history so I imported the readline module. Importing the readline module (and not even using it) will unlock these features. This code works perfectly:

import readline

while True:
    cmd = input('> ')
    if cmd == 'exit':
        break

My problem (or maybe just annoyance) is that PyCharm gives me a non-fatal warning that I have an unused import statement. I assume this is just a simple fault in PyCharm for not realizing that the readline import WILL be used if you use the builtin input function.

What is the cleanest way for me to get rid of this warning? Also, is this a bug that PyCharm ought to fix?


回答1:


PyCharm linting only goes so far, but you can at least supress the warning by writing:

# noinspection PyUnresolvedReferences
import readline

You can access general warning configurations in Settings > Editor > Inspections.

Also if you ever need to suppress a warning type, but just for a single line/function instead of the whole file, do this:

  • place the cursor where the warning is
  • press Alt+Enter
  • press right arrow key on the "light bulb icon"
  • press Enter on the "suppress for class/function/statement"

PyCharm automatically adds the appropriate comment that ignores the warning type caused by that statement.



来源:https://stackoverflow.com/questions/61279148/pycharm-says-readline-import-not-being-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!