When/where should I check for the minimum Python version?

大城市里の小女人 提交于 2019-12-05 17:25:48

The primary point of a compatibility check is to have this check either elegantly handle a compatibility issue or gracefully exit with an explanation before the incompatibility causes problems.

I'd put it near the top of setup.py, or the first script that belongs to you that will be called. Best practice is not to include code in __init__.py (unless you're making a MAJOR package, I'd opine), but if you already have a lot of code there, it's fine.

The quickest point of reference I can find: The old Python 2.6 unittest module had a test for it near the top, naturally, after the module docstring, imports, and __all__.

Another point of reference shows a compatibility check in an __init__.py, again, near the top, though here it is immediately after the docstring and an import of sys, required for the check. There are other similar examples of this usage in __init__.py in this same set of libraries.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!