Typing Feature Flags
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 1.8k
- フォーク
- 302
- 平均マージ
- 23時間
- マージ済み PR(30日)
- 8
説明
This idea is similar to stricter stubs idea, but a bit more general and focused more on new typing features. Typing features are produced at pretty quick pace. We're currently producing several typing peps each year. Paramspec, dataclasses, variadic, literal string, positional only, and so on. It looks like pace of a couple typing peps will continue for awhile.
We currently have multiple major type checkers. As new typing features are proposed, support for those features will appear in each type checker at different times. For typeshed and libraries that want to be typed and could gain type safety from using newer features, there's a problem of using too new feature may cause some user's experience to worsen if the type checker they use lacks support for that feature. So currently it looks like typeshed has a checklist of PEP accepted + support by each major type checker.
My proposal is intruding feature flags corresponding to major new typing features. We could have several bool constants like,
class TypingFeatures:
PARAMSPEC_SUPPORTED = ...
VARIADIC_SUPPORTED = ...
LITERAL_STRING_SUPPORTED = ...
in typing.py/typing_extensions.py and then both stubs/libraries could use,
if TypingFeatures.PARAMSPEC_SUPPORTED:
def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, ContextManager[_T]]: ...
else:
def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ...
shortly after PEP/typing feature is accepted. The semantics of TypingFeatures.PARAMSPEC_SUPPORTED would be like TYPE_CHECKING except each type checker will define each feature as True/False.
I think this mainly applies to typing features that allow additional safety/make system more powerful. Features that only improve readability while important would not have value with a feature flag because while,
alias1 = int | str
is better then,
alias1 = Union[int, str]
but using a feature flag here makes it even less readable for no gain,
if TypingFeatures.UNION_OPERATOR:
alias1 = int | str
else:
alias1 = Union[int, str]
I'm mostly thinking of this for new/recent PEPs. The one other feature I'd be interested in a flag for is recursive types as it's very popular requested feature that different type checkers have different support for.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まずこの提案を、リンクされているより厳格なスタブに関する issue と併せて読み、その後、typing.py と typing_extensions.py が現在 TYPE_CHECKING のような機能関連の定数をどのように公開しているかを調べてください。実装を完了と見なすには、その前に、機能フラグとそのセマンティクスについて確定した設計が issue に必要です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100