“Unused import warning” and pylint

醉酒当歌 提交于 2019-12-03 22:13:28

The approach I would use is to use loggingsetup as a sort of wrapper for logging.

import logging

# set up logging config here

from logging import *

Then in your other modules you:

import loggingsetup as logging

You might want to use a name other than loggingsetup in this case, e.g. tweaked_logging or logging_with_my_settings.

sthenault

In such cases, you can still explicitly tell pylint that this unused import in intended:

import loggingsetup # pylint: disable=unused-import

Notice the instruction is on the same line as the import so W0611 is only disabled for this line, and not for all the block below.

If you use pylint and flake8 you can ignore unused import warning in both tools in this way:

import loggingsetup  # noqa # pylint: disable=unused-import

your code should be in a function called once in the main script

As you have mentioned yourself wrapping it in a function and calling the setup explicitly would resolve this warning. And as Steven mentioned, this would be considered better code since it is more explicit about what you are doing.

If you worry about calling this function twice, you can of course use a module intern flag to allow execution of the function body only once.

__initialized = False

def init():
    if not __initialized:
        __initialized = True
        #DoStuff

Here is how you could satisfy the warning (vscode + pylint);

from array import array
ar = array('i', [])

So instead of using a wild card, specified "array" method again.

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