Inconsistent behavior w.r.t missing builtins
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Issue
Some of the builtins fixtures are sparse to the point that they're missing even the declaration of dict, list, tuple etc. types. The austerity is justified by improved tests performance, and it's understood that specific tests can specify a broader fixture without slowing down other tests.
However, some core features rely on the presence of those types, e.g.
- functions'
**kwargs - modules'
__annotations__ namedtuple's attributes like_field_types
I've observed 3 different strategies used to handle the types absence:
- crash (example:
**kwargshandling) - give up (example:
__annotations__not being added) - fallback to
object(example:NamedTupleattributes)
I think we should recommend and, ideally, consolidate on one strategy.
Motivation
Case in point: Recently while implementing #14526, I had to "play" a whack-a-mole with unrelated tests breaking. I've used **kw which required me to add dict to a number of builtins fixtures, which in turn caused __annotations__ to materialize where they didn't before, and failed some other tests.
I think ideally we shouldn't have this whack-a-mole, and tests should be less brittle.
Recommendation
Which strategy to adopt? While it's good practice to structure code to be more testable, I think it's normally discouraged to have code paths that are only due to testing. Since those builtins should universally exist in "production", I think crash should be our strategy.
Since code typically relies only on the presence of those classes (not their methods), we can put in place a rule (validated by tests) that any builtins fixture must define a baseline of types, even if empty. This shouldn't affect performance greatly, and provide a comfortable baseline.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、mypy/types.py、mypy/semanal.py、mypy/semanal_namedtuple.py における不足している builtins の処理を、影響を受ける builtins の fixture とテストとともに比較します。必要な builtin 宣言に対する一貫した戦略を決定し、**kwargs、annotations、および NamedTuple の処理全体で fixture の動作が安定するよう、関連するテストを更新します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- リファクタリング
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 35/100