Pylint报告没有导入的文件循环导入

Ale*_*sen 2 python pylint flask python-3.x

所以Pylint(1.4.3)报告循环导入,它没有多大意义.首先,报告的文件没有import语句.

其次没有文件导入参考文件.__init__.py文件从development_config(有问题的文件)加载配置值,但没有文件导入该文件.

那么为什么Pylint会给我这个警告呢?

Pylint警告

************* Module heart_beat.development_config
R:  1, 0: Cyclic import (heart_beat -> heart_beat.views -> heart_beat.models) (cyclic-import)
R:  1, 0: Cyclic import (heart_beat -> heart_beat.views) (cyclic-import)
Run Code Online (Sandbox Code Playgroud)

development_config

""" -------------------------- DATA BASE CONFINGURATION --------------------"""
SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/test.db'
SQLALCHEMY_ECHO = False

""" -------------------------- Flask Application Config --------------------"""
THREADS_PER_PAGE = 8
VERSION = "0.1"
Run Code Online (Sandbox Code Playgroud)

__init__.py

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

#from register_assets import register_all

app = Flask(__name__, static_url_path='/static')

# the environment variable LIMBO_SETTINGS is set in runserver, run_unit_tests
# or limbo.wsgi.

def load_configs():
    """Take all configs found in development_config.py."""
    app.config.from_pyfile("development_config.py", silent=False)

load_configs()

# global SQLAlchemy configuration
db = SQLAlchemy(app)

#Create and register all static asset bundles.
#register_all(app)

#NOTE: DON'T LISTEN TO YOUR IDE! heart_beat.views is used and required.
import heart_beat.views  # views contains all URL routes, Importing sets routes.
def setup_db():
    """Database creation in a file rather then a statement for easier tests."""
    db.create_all()

def teardown_db():
    """Database deletion in a file rather then a statement for easier tests."""
    db.drop_all()

setup_db()
Run Code Online (Sandbox Code Playgroud)

views.py

from flask import request

from . import app
from . import db
from . import models
from . import exceptions as ex
Run Code Online (Sandbox Code Playgroud)

models.py

import datetime

from . import exceptions
from . import db
from . import app
Run Code Online (Sandbox Code Playgroud)

cod*_*ife 6

我相信这是目前pylint中的一个错误.需要对多个模块进行分析的事情(例如cyclic-importduplicate-code检测)会被作为重构抛入最后解析的模块文件中.对我来说,这最终成为一个空__init__.py文件,其中有两个都掉进了它.

这两个重构消息都包含有问题的实际模块名称:

  • 对于循环导入,有问题的模块列在括号中
  • 对于重复代码,有问题的模块列在以下行中 ==

这些的分组不仅限于模块的打印输出,它还会影响摘要报告% errors / warnings by module,其中最终解析的文件获取重构的计数,而实际关注的模块都不会从中获取任何计数.

  • 是否有办法在不完全禁用“循环导入”和“重复代码”的情况下禁用这些误报? (4认同)