Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Read/write property does not work with "allow_interpreted_subclasses" #15828

Copy link
Copy link
Open
@feibl

Description

@feibl
Issue body actions

Bug Report

Code generated by mypyc crashes at run-time when accessing a read/write property of an interpreted subclass.

To Reproduce

The mypyc code:

#entity.py
from mypy_extensions import mypyc_attr


@mypyc_attr(allow_interpreted_subclasses=True)
class EntityBase:

    def __init__(self) -> None:
        self._name = 'hello'

    @property
    def name(self) -> str:
        return self._name

    @name.setter
    def name(self, name: str):
        self._name = name


def print_name_property(entity: EntityBase):
    print(f'Property {type(entity)}: {entity.name}')

The driver code:

from reproducer import print_name_property, EntityBase


class EntitySubclass(EntityBase):

    def __init__(self):
        super().__init__()


def main():
    entity_subclass = EntitySubclass()

    print_name_property(entity_subclass)


if __name__ == '__main__':
    main()

Expected Behavior

The code should print 'hello' regardless if the attribute is accessed directly or via property.

Actual Behavior

Program crashes, when calling print_name_property(entity_subclass):

Traceback (most recent call last):
  File "/home/python/mypyc/reproducer.py", line 17, in <module>
    main()
  File "/home/python/mypyc/reproducer.py", line 13, in main
    print_name_property(entity_subclass)
  File "entity.py", line 20, in print_name_property
    print(f'Property {type(entity)}: {entity.name}')

AttributeError: 'EntitySubclass' object has no attribute '__mypyc_setter__name'

Process finished with exit code 1

Your Environment

  • Mypy version used: 1.4.1
  • Python version used: 3.11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongmypy got something wrongtopic-mypycmypyc bugsmypyc bugs

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.