Skip to content

Type override for attributes is not checked #2211

Closed

Description

@dmoisset

from what I see, overriding an attribute with an incompatible type (which can lead to unsoundness) does not produce any kind of warning with mypy:

class Base:
    attr = "foo"

    def f(self) -> str:
        return self.attr

class Derived(Base):
    attr = 42

d = Derived()

reveal_type(d.f())

The code above shows that mypy thinks that the d.f() expression is a string, while it's actually an int. Shouldn't this kind of redefinitions be forbidden?

Activity

  1. gvanrossum commented on Oct 3, 2016

    @gvanrossum
    Member
  2. dmoisset commented on Oct 3, 2016

    @dmoisset
    ContributorAuthor

    I have looked before opening but couldn't find one... After a second look, there's a mention to this in #1338 , but they seem to be two related but distinct issues.

  3. gvanrossum commented on Oct 3, 2016

    @gvanrossum
    Member
  4. gvanrossum commented on Jan 27, 2017

    @gvanrossum
    Member

    Fixed by #2510.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions