python / python/mypy

stubtest and @deprecated

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

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

bug topic-pep-702 topic-stubtest
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

Bug Report

The @warnings.deprecated decorator adds a few dunders to classes it decorates. This causes stubtest to complain about differences between stub and implementation, unless these changes are added manually to the stubs. I think we should special case @deprecated to ignore these differences.

To Reproduce

For example, adding the following test to StubtestUnit:

    @collect_cases
    def test_deprecated(self) -> Iterator[Case]:
        yield Case(
            stub="""
            from warnings import deprecated

            @deprecated("")
            class Foo: ...
            """,
            runtime="""
            from warnings import deprecated

            @deprecated("")
            class Foo:
                pass
            """,
            error=None,
        )

causes the following error when running the tests with Python 3.13:

E           AssertionError: error: test_module.Foo.__deprecated__ is not present in stub
E             Stub: in file test_module.pyi
E             MISSING
E             Runtime:
E             ''
E             
E             error: test_module.Foo.__init_subclass__ is not present in stub
E             Stub: in file test_module.pyi
E             MISSING
E             Runtime: in file /opt/pyenv/versions/3.13.8/lib/python3.13/warnings.py:621
E             def (*args, **kwargs)
E             
E             error: test_module.Foo.__new__ is not present in stub
E             Stub: in file test_module.pyi
E             MISSING
E             Runtime: in file /opt/pyenv/versions/3.13.8/lib/python3.13/warnings.py
E             def (*args, **kwargs)
E             
E             Found 3 errors (checked 1 module)
E             
E           assert {'test_module....Foo.__new__'} == set()
E             
E             Extra items in the left set:
E             'test_module.Foo.__deprecated__'
E             'test_module.Foo.__new__'
E             'test_module.Foo.__init_subclass__'
E             Use -v to get more diff

Interestingly, this is different from what we see in typeshed (python/typeshed#14893):

error: jwcrypto.jwt.JWTMissingKeyID.__init_subclass__ is inconsistent, stub does not have *args parameter "args"
Stub: in file /home/runner/work/typeshed/typeshed/stubs/jwcrypto/jwcrypto/jwt.pyi:139
def (cls: type[builtins.object])
Runtime: in file /opt/hostedtoolcache/Python/3.13.8/x64/lib/python3.13/warnings.py:621
def (*args, **kwargs)

Your Environment

  • Mypy version used: master for the test above, 1.18.2 in typeshed CI
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.13

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

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

はじめの一歩

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

調査の方向性

StubtestUnit にある提案されたテストから始め、Python 3.13 で再現してください。warnings.deprecated でデコレートされたクラスに対する stubtest の比較を追跡し、デコレーターによって追加された差分だけを無視してテストが成功するようにしてください。

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

評価

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

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

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