Skip to content

Mypy expects @property's to follow each other #7263

Closed
@mchlnix

Description

@mchlnix
  • Are you reporting a bug, or opening a feature request?
    Bug
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
class Works:
    def __init__(self):
        self._a = 0

    @property
    def a(self):
        return self._a

    @a.setter
    def a(self, value):
        self._a = value


class Doesnt:
    def __init__(self):
        self._a = 0

    @property
    def a(self):
        return self._a

    def another_method(self):
        print("This is unimportant")

    @a.setter
    def a(self, value):
        self._a = value
  • What is the actual behavior/output?
test-mypy.py:25: error: Name 'a' already defined on line 18
test-mypy.py:25: error: "Callable[[Any], Any]" has no attribute "setter"
  • What is the behavior/output you expect?
    That parts of a property definition do not have to follow each other directly to be recognized as such.
  • What are the versions of mypy and Python you are using?
    Python: 3.6.5
    Mypy: 0.720
  • Do you see the same issue after installing mypy from Git master?
    Yes
  • What are the mypy flags you are using? (For example --strict-optional)
    None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions