python / python/typing_extensions

TypeError: Parameter list cannot be empty for TypeVarTuple

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

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

pep-646
主要言語
Python
スター
583
フォーク
146
平均マージ
10時間 11分
マージ済み PR(30日)
5

説明

There is a problem with typing_extensions that doesn't happen with typing. Running the program with python3.11 works, but with python3.10 with typing_extensions throws:

Traceback (most recent call last):
  File ".../main.py", line 48, in <module>
    main()
  File ".../main.py", line 40, in main
    signal: Signal[()] = Signal[()]()
  File "/usr/lib/python3.10/typing.py", line 312, in inner
    return func(*args, **kwds)
  File "/usr/lib/python3.10/typing.py", line 1328, in __class_getitem__
    raise TypeError(
TypeError: Parameter list to Signal[...] cannot be empty

from __future__ import annotations

from typing_extensions import Callable, TypeVarTuple, Generic, Unpack, List, TypeVar

VarArgs = TypeVarTuple('VarArgs')


class Signal(Generic[Unpack[VarArgs]]):

    def __init__(self):
        self.functions: List[Callable[..., None]] = []
        """
        Simple mechanism that allows abstracted invocation of callbacks. Multiple callbacks can be attached to a signal
        so that they are all called when the signal is emitted.
        """

    def connect(self, function: Callable[..., None]):
        """
        Add a callback to this Signal
        :param function: callback to call when emited
        """
        self.functions.append(function)

    def emit(self, *args: Unpack[VarArgs]):
        """
        Call all callbacks with the arguments passed
        :param args: arguments for the signal, must be the same type as type parameter
        """
        for function in self.functions:
            if args:
                function(*args)
            else:
                function()


def main():
    def signalEmptyCall():
        print("Hello!")

    signal: Signal[()] = Signal[()]()

    signal.connect(signalEmptyCall)

    signal.emit()


if __name__ == '__main__':
    main()

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

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

はじめの一歩

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

調査の方向性

main.py の再現コードから始め、Python 3.10 で typing_extensions を使用した場合と Python 3.11 で typing を使用した場合の Signal[()] の動作を比較します。TypeVarTuple と空のパラメーターの処理を追跡し、その後、空のパラメーターリストが一貫して受け入れられることを示す回帰テストを追加または更新します。

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

評価

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

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

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