python / python/mypy

Dotted decorators on `TypedDict` classes fails for a certain package layout

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

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

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

説明

Bug Report, To Reproduce, & Actual Behaviour

I'm hitting a strange error in data_structures.py with the following project structure, with a potential culprit in runtime_validation.py:

Project/
└── package/
    ├── __init__.py
    ├── data_structures.py
    └── runtime_validation.py
  • Contents of data_structures.py
    import typing as tp
    import package.runtime_validation as _runtime_validation
    # from package.runtime_validation import register_runtime_validator  # Uncomment to make errors disappear
    
    deco = _runtime_validation.register_runtime_validator  # OK
    
    @_runtime_validation.register_runtime_validator  # OK
    class A: ...
    
    @_runtime_validation.register_runtime_validator  # E: Module has no attribute "register_runtime_validator"
    class TD(tp.TypedDict): ...
    
  • Contents of __init__.py
    import typing as tp
    
    RUNTIME_VALIDATORS: tp.Final = ...
    
    from package.data_structures import TD
    
  • Contents of runtime_validation.py
    import typing as tp
    
    from package import RUNTIME_VALIDATORS  # Comment out to make errors in `data_structures.py` disappear
    
    def register_runtime_validator(Type: type[tp.Any], /) -> type[tp.Any]:
        ...
        return Type
    

Expected Behavior

No issues

Your Environment

  • Mypy version used: 1.11.1
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10.11

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

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

はじめの一歩

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

調査の方向性

data_structures.py、init.py、runtime_validation.py に示されているパッケージの構成と内容を使い、mypy 1.11.1 で問題を再現してください。まず、import cycle が TypedDict クラス上のドット付き decorator の属性検索にどのような影響を与えるかを追跡してください。直接 import のコメントを解除しなくても、例で missing-attribute エラーが報告されなければ完了です。

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

評価

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

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

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