gpt4 book ai didi

python - 为什么语法从 flask.ext.* 更改为 flask_*?

转载 作者:太空宇宙 更新时间:2023-11-04 09:55:29 24 4
gpt4 key购买 nike

看起来好像有弃用。那是怎么决定的? Python 3 和 Python 2 之间有区别吗?

最佳答案

flask.ext was deprecated in issue #1135 ,创建于 2014 年。实际弃用通知于 2016 年启用。reasoning behind the deprecation is :

Some introductory information for new contributors:

Flask used to have flaskext as a namespace for extensions, so they were importable as flaskext.foo. This didn't work well, so the new form flask_foo was introduced. flask.ext.foo is a compatibility layer that will try to import both variants. See http://flask.pocoo.org/docs/0.10/extensions/

flask.ext.foo is hard to maintain, and since now all extensions have switched to the new package naming scheme, it is no longer worth it. We want to deprecate it for 1.0, so we need some sort of tool which can help users to rewrite all their old imports in their apps.

One could write a Python script similar to this beast. This will get the job done, but as its docstring says, it's a terrible hack.

lib2to3 proved useful for writing larger migration tools, but it's nontrivial to use it.

  • https://github.com/mitsuhiko/python-modernize/ is one based on it, and it seems to me that's the easiest project one could rip off from.
  • I wasn't able to find complete tutorials that are useful for this. Most seem to be focused on porting to Python 3, which would imply running the default 2to3 fixers on the user's codebase (which we definetly don't want)
  • One will have to read the sourcecode of 2to3 and lib2to3 to understand, i think. This is doable by entering libraryname hg.python.org into Google, where the libraryname is either 2to3 or lib2to3.
  • The current state for doing sourcecode manipulation in Python sucks, and i'd like to see a library which wraps lib2to3 and provides a more concise API.

旧的 .ext 是一个兼容层,用于支持旧的 flaskext 模块,同时等待 flask_ 标准化。

这将 flask. 命名空间与每个模​​ block 的命名空间分开,因为模块现在完全存在于它自己的模块 (flask_module) 中,而不是被加载到通用命名空间中Flask 中的所有扩展。更清楚的是,该模块并未捆绑为 Flask 的一部分。

关于python - 为什么语法从 flask.ext.* 更改为 flask_*?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46050635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com