`AbstractContextManger.__enter__` should be abstract
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 5.1k
- フォーク
- 2.1k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 82
説明
Code sample in basedpyright playground
from contextlib import AbstractContextManager
from typing import override
class CM(AbstractContextManager[int]):
@override
def __exit__(self, *_): ...
with CM() as i:
print(i + 1)
AbstractContextManger.__enter__ has a default implementation that returns self, so by making it abstract you would require implementations to provide the correct implementation. this would force a redundant implementation if the type is Self, but that is currently impossible to type anyway: https://discuss.python.org/t/self-as-typevar-default/90939
even without Self support, it is only one line of redundant code: def __enter__(self) -> Self: return self
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
basedpyright playground example と、それが検証する AbstractContextManager stub entry point から始めます。現在のデフォルトの enter が抽象クラスのチェックにどのような影響を与えるかを確認し、その後、それを抽象化すると実装が必要になることを、意図されたコンテキストマネージャーの型付け動作を維持したまま検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100