Skip to content

Better error message for incompatible assignment to method #4507

Open
@anxolerd

Description

@anxolerd

Note

I am not sure whether it should be reported here or to the typeshed repo. Reporting here for now. If this is a typeshed issue, I'll gladly open issue there and close this one.

If there is something special in index field in NamedTuple, please point out to the corresponding documentation as I failed to find anything on topic.

Description

Type

bug

Code to check

from typing import NamedTuple


class Foo(NamedTuple):
    index: str

Actual behavior

test.py:5: error: Incompatible types in assignment (expression has type "str", base class "tuple" defined the type as "Callable[[Tuple[str, ...], Any, int, int], int]")

Expected behavior

No errors while typechecking

Environment

$ mypy -V
mypy 0.560
$ python -V
Python 3.6.4

Behavior is still the same when using mypy from master:

$ mypy -V
mypy 0.570-dev-7192a7578fc47530bbb5382984d289bffa72b30b
$ mypy test.py
test.py:5: error: Incompatible types in assignment (expression has type "str", base class "tuple" defined the type as "Callable[[Tuple[str, ...], Any, int, int], int]")

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions