无法找到模块的限定名称:main.py — in 是什么意思?

问题描述 投票:0回答:1

我正在使用 wemake-python-styleguide 来检查我的代码,其中一项检查会为每个 Python 文件输出此消息。

所以,我的问题是:这是什么意思,linter 想要看到什么?

我搜索了 google、stackoverflow、linters git 和 chatGPT,但没有找到答案!

python pep8 linter
1个回答
0
投票

您没有分享太多细节,所以我只是猜测。我想这就是正在运行的代码:Bandit。这是记录您看到的消息的部分:

    # in some cases we can't determine a qualified name
    try:
        self.namespace = b_utils.get_module_qualname_from_path(fname)
    except b_utils.InvalidModulePath:
        LOG.warning(
            "Unable to find qualified name for module: %s", self.fname
        )
        self.namespace = ""
    LOG.debug("Module qualified name: %s", self.namespace)

b_utils.get_module_qualname_from_path(fname)
在您的情况下返回
InvalidModulePath
异常。如果您检查引发该异常的原因,就会发现路径无法分为两部分。

def get_module_qualname_from_path(path):
    """Get the module's qualified name by analysis of the path.

    Resolve the absolute pathname and eliminate symlinks. This could result in
    an incorrect name if symlinks are used to restructure the python lib
    directory.

    Starting from the right-most directory component look for __init__.py in
    the directory component. If it exists then the directory name is part of
    the module name. Move left to the subsequent directory components until a
    directory is found without __init__.py.

    :param: Path to module file. Relative paths will be resolved relative to
            current working directory.
    :return: fully qualified module name
    """

    (head, tail) = os.path.split(path)
    if head == "" or tail == "":
        raise InvalidModulePath(
            'Invalid python file path: "%s"'
            " Missing path or file name" % (path)
        )

    [code continues]

所以我认为您正在运行从

.py
文件所在的同一目录运行的任何内容,这意味着
head
os.path.split(path)
将为空。尝试将
.py
文件放入子目录中,然后查看消息是否消失。

© www.soinside.com 2019 - 2024. All rights reserved.