Skip to content

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

Description

@nstarman

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-descriptorsProperties, class vs. instance attributestopic-mypycmypyc bugs

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions