python / python/typing

Conditionally load stubs based on specific version of package installed

未关闭
#693 1 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

topic: feature
主要语言
Python
星标
1.8k
派生
302
平均合并
23 小时
30 天内合并 PR
8

描述

For django-stubs, we would like to be able to load stubs conditionally, like it's done for typeshed via https://mypy.readthedocs.io/en/latest/common_issues.html#python-version-and-system-platform-checks

See https://github.com/typeddjango/django-stubs/issues/262

I'd like to propose to add a special function is_package_installed for stub files:

if is_package_installed('Django>=3.0.*')
    class Django30Class: ...
else:
    class Django22Class: ...

which will evaluate according to the rules specified in PEP440 https://www.python.org/dev/peps/pep-0440/#version-specifiers

It was discussed in https://github.com/python/typeshed/issues/153, current workaround seems to be (from https://github.com/python/typeshed/issues/153#issuecomment-389198282):

release and install a separate stub package for each version of the library

I believe it's too complex, as one needs to maintain lots of separate branches for specific versions of the supported package. And versioning of the stubs package would then be PACKAGE_VERSION.STUBS_VERSION_INCREMENT?

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

先阅读链接的 mypy 文档和 PEP 440 的版本说明符规则,然后阅读所引用的 django-stubs 和 typeshed 讨论。提议的行为是一种根据已安装软件包的版本有条件地选择 stub 声明的设计;要完成此项工作,需要一个达成共识的机制,以及针对受支持版本检查的文档化行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
tooling
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。