Skip to content

Mypy cannot determine the type of the declared field inside a protocol method #13700

@UniverseFly

Description

@UniverseFly

Bug Report

Mypy cannot determine the type of the declared field inside a protocol method.

To Reproduce

Invoke mypy on the following Python file

# bug.py
from typing import Protocol

class Test(Protocol):
    k: int

    def test(self, i: int):
        self.k = self.k

Mypy complains: bug.py:7: error: Cannot determine type of "k". Strange here is if I remove the parameter i, the error would disappear.

Expected Behavior

No such error.

My Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions