python / python/typing

Spec and conformance tests disagree on converting constructors into callable for classes with `__new__` and `__init__`

オープン
#2,158 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

topic: conformance tests topic: typing spec
主要言語
Python
スター
1.8k
フォーク
302
平均マージ
23時間
マージ済み PR(30日)
8

説明

For classes with both __new__ and __init__, when converting the constructor into a Callable, the spec says that

https://github.com/python/typing/blame/20096eeba502b1bf955fcf62b389adbaa63fc61b/docs/spec/constructors.rst#L457

    class B:
        """ __new__ and __init__ """
        def __new__(cls, *args, **kwargs) -> Self:
            ...

        def __init__(self, x: int) -> None:
            ...

    reveal_type(accepts_callable(B))  # ``def (*args, **kwargs) -> B | def (x: int) -> B``

The conformance test says that

https://github.com/python/typing/blob/20096eeba502b1bf955fcf62b389adbaa63fc61b/conformance/tests/constructors_callable.py#L54-L64

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

docs/spec/constructors.rst のリンクされたセクション付近に記載されているコンストラクターの動作を、conformance/tests/constructors_callable.py のケースと比較してください。newinit の両方を定義するクラスに対して意図されている callable の型を特定し、その後、仕様と適合性テストを一致させ、関連するコンストラクター適合性チェックを実行してください。

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

評価

技術スタック
python
領域
documentation, testing-qa
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

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

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