所以Pylint
(1.4.3
)报告循环导入并没有多大意义。
首先,报告的文件没有import语句。
其次没有文件导入参考文件。 __init__.py
文件从development_config
(有问题的文件)加载配置值,但没有文件
导入说文件。
那么为什么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)
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"
__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()
views.py
from flask import request
from . import app
from . import db
from . import models
from . import exceptions as ex
models.py
import datetime
from . import exceptions
from . import db
from . import app
答案 0 :(得分:6)
我相信这是目前pylint中的一个错误。需要对多个模块进行分析的事情(例如cyclic-import
和duplicate-code
检测)会被作为重构抛入最后解析的模块文件中。对我来说,这最终成为一个空的__init__.py
文件,其中包含这两个文件。
这两个重构消息虽然包含有问题的实际模块名称:
==
这些的分组不仅限于模块的打印输出,它还会影响摘要报告% errors / warnings by module
,其中最终解析的文件获取重构的计数,而实际关注的模块都没有得到任何来自他们的计数。