Skip to content

Types of class member variables are not checked #2243

Closed
@kencoken

Description

@kencoken

Running mypy on the following class, using Python 3.6 support (PEP 526):

class TestClass:

    a: str = 9

    def __init__(self):

        self.b: str = 8
        self.b = 12

    def test_method(self):
        self.b = 50

Results in the following output:

another_test.py: note: In class "TestClass":
another_test.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "str")

It seems as if the type of the member variable b is not checked.

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