PyCharm 解析 - flask.ext.sqlalchemy 与 flask_sqlalchemy [英] PyCharm resolving - flask.ext.sqlalchemy vs flask_sqlalchemy

查看:36
本文介绍了PyCharm 解析 - flask.ext.sqlalchemy 与 flask_sqlalchemy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在我的应用程序中使用以下格式,一切正常,除了 PyCharms 解析/自动完成功能:

If I use the following format in my application, everything works, except PyCharms resolving / autocomplete feature:

from flask.ext.sqlalchemy import SQLAlchemy

如果我在我的应用程序中使用以下格式,一切正常.但是,唉,这不是导入库的正确方法:

If I use the following format in my application, everything works. But, alas, it is not the correct way to import the libraries:

from flask_sqlalchemy import SQLAlchemy

有什么方法可以让 PyC​​harm 正确解析第一个语法?

Is there any way to make PyCharm resolve the first syntax correctly?

推荐答案

flask.ext命名空间是一个transition命名空间,见Flask Extension Development 文档的Extension Import Transition部分:

The flask.ext namespace is a transistion namespace, see the Extension Import Transition section of the Flask Extension Development docs:

有一段时间我们建议使用命名空间包来扩展 Flask.这在实践中被证明是有问题的,因为存在许多不同的竞争命名空间包系统,并且 pip 会在不同的系统之间自动切换,这给用户带来了很多问题.

For a while we recommended using namespace packages for Flask extensions. This turned out to be problematic in practice because many different competing namespace package systems exist and pip would automatically switch between different systems and this caused a lot of problems for users.

Flask 扩展应该敦促用户从 flask.ext.foo 导入而不是 flask_fooflaskext_foo 以便扩展可以转换到新的包名而不影响用户.

Flask extensions should urge users to import from flask.ext.foo instead of flask_foo or flaskext_foo so that extensions can transition to the new package name without affecting users.

所以为了在版本之间transition,添加了flask.ext别名,它会自动尝试导入flask_[name]包导入 flask.ext.[name].但这种转变现在没有实际意义.您不再会发现仍然完全依赖于 flask.ext 的软件包.

So to transition between versions, the flask.ext alias was added, which will automatically try to import flask_[name] packages when importing flask.ext.[name]. But that transition is now moot; you no longer will find packages that still rely solely on flask.ext.

因此,完全可以使用实际的模块名称并让 PyC​​harm 自动完成模块内容.

As such, it is perfectly fine to use the actual module name and have PyCharm autocomplete the module contents.

如果您仍在使用旧版本的扩展程序并且需要与未来兼容,那么您只有真正必须使用 flask.ext.未来已经到来.

You only really have to use flask.ext if you are still using an older version of the extension and need to be future compatible. That future is already here.

这篇关于PyCharm 解析 - flask.ext.sqlalchemy 与 flask_sqlalchemy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆