python / python/mypy

[mypyc] property setter and deleter don't work with parameterized attributes

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

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

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

説明

Bug Report

mypyc fails to compile a class with a property setter and deleter and a weakref attribute.

To Reproduce

  1. Defined (in a file foo.py) a class Bar with a property that has a setter and deleter and weakref attribute.
  2. run mypyc foo.py3.

e.g.

from __future__ import annotations
from typing import TypeVar, Generic
import weakref

T = TypeVar("T")

class Bar(Generic[T]):
    _attr: weakref.ReferenceType[T] | None
    def __init__(self) -> None:
        self._attr = None
    @property
    def attr(self) -> T | None:
        return self._attr() if self._attr is not None else None
    @attr.setter
    def attr(self, value: T) -> None:
        self._attr = weakref.ref(value)
    @attr.deleter
    def attr(self) -> None:
        self._attr = None

Actual Behavior

I get the following error:

File "mypyc/irbuild/classdef.py", line 87, in transform_class_def
File "mypyc/irbuild/classdef.py", line 200, in add_method
File "mypyc/irbuild/function.py", line 369, in handle_ext_method
File "mypyc/irbuild/function.py", line 312, in gen_func_item
File "mypyc/irbuild/function.py", line 351, in gen_func_ir
...: KeyError: <mypy.nodes.FuncDef object at 0x7f93d4876b80>

This error does not occur when setter and deleter are omitted.

Your Environment

  • Mypy version used: 0.950
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.9
  • Operating system and version: macOS Monterey, version 12.4

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

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

はじめの一歩

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

調査の方向性

foo.py の例で失敗を再現し、その後、報告されたパスを mypyc/irbuild/classdef.pymypyc/irbuild/function.py を通して追跡します。property setter と deleter を持つパラメーター化された属性のカバレッジを追加し、mypyc foo.pyKeyError なしでコンパイルできれば issue 完了とします。

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

評価

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

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

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