PyCharm resolving - flask.ext.sqlalchemy vs flask_sqlalchemy(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
有什么方法可以让 PyCharm 正确解析第一个语法?
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_foo
或 flaskext_foo
以便扩展可以转换到新的包名而不影响用户.
Flask extensions should urge users to import from
flask.ext.foo
instead offlask_foo
orflaskext_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
.
因此,完全可以使用实际的模块名称并让 PyCharm 自动完成模块内容.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PyCharm 解析 - flask.ext.sqlalchemy 与 flask_sqlalchemy


- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01