python / python/typing

Conditionally load stubs based on specific version of package installed

オープン
#693 コメント 1 件 リアクション 4 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

topic: feature
主要言語
Python
スター
1.8k
フォーク
302
平均マージ
23時間
マージ済み PR(30日)
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされている mypy のドキュメントと PEP 440 のバージョン指定子の規則から始め、続いて参照されている django-stubs と typeshed の議論を読んでください。提案されている動作は、インストール済みパッケージのバージョンに基づいてスタブ宣言を条件付きで選択するための設計です。完了には、合意された仕組みと、サポート対象のバージョンチェックに関する文書化された動作が必要です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。