python / python/mypy

Bug report (Regression): bad overload resolution in `--strict` mode

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

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

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

説明

Bug Report

The following code type-checked with mypy 1.16.1 in --strict mode but does not type-check with mypy 1.17 and the master branch (currently eb07c060c) in --strict mode. Bisecting points to the commit 33d1eedc0.

Note that the problem does not occur if --strict mode is disabled.

To Reproduce

import inspect
import typing
from typing import Any, ClassVar

def is_classvar(cls: type, scope: dict[Any, type]) -> bool:
    ann = inspect.get_annotations(cls, eval_str=True, locals=scope).get("kind")
    if ann is None:
        raise Exception("Should be annotated.")
    return typing.get_origin(ann) is not ClassVar

Actual Behavior

mypy --strict test_any.py
test_any.py:9: error: Non-overlapping identity check (left operand type: "ParamSpec", right operand type: "<typing special form>")  [comparison-overlap]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 1.17 and master (bad), mypy 1.16.1 (good)
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.13

Note that reveal_type(ann) gives Any | None and that annotating ann: Any | None solves the problem.

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

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

はじめの一歩

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

調査の方向性

test_any.py の再現コードと、コミット 33d1eedc0 によって導入された動作から始めます。影響を受けるバージョンと、以前は動作していたバージョンで例に対して mypy --strict を実行します。例が明示的な ann: Any | None アノテーションを必要とせずに --strict で型チェックに通れば完了です。

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

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
52/100

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

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