Skip to content

Setter and getter method names can't differ (Python 2) #8086

Closed
@JukkaL

Description

@JukkaL

This doesn't work (reported by Tim Abbott):

class C:
    def __init__(self) -> None:
        self._x = 0

    @property
    def x(self) -> int:
        return self._x

    @x.setter
    def set_x(self, value: int) -> None:   # Note the name of the method! "def x" works.
        self._x = value

This example seems to be only valid in Python 2, not Python 3.

(Originally reported in #220 (comment).)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions