This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: typing.NamedTuple: type-checking error when "index" used as member
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: campkeith, gvanrossum, levkivskyi, rhettinger
Priority: normal Keywords:

Created on 2018-07-20 21:08 by campkeith, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg322038 - (view) Author: Keith Campbell (campkeith) Date: 2018-07-20 21:08
Find the test case below:

----
from typing import NamedTuple

class Foo(NamedTuple):
    alpha: int
    index: int
----

This results in the following error when run through type-checking with mypy:

----
% mypy --version
mypy 0.620
% mypy go.py
go.py:5: error: Incompatible types in assignment (expression has type "int", base class "tuple" defined the type as "Callable[[Tuple[int, ...], Any, int, int], int]")
----

When I instantiate this class in the python interpreter, I have no problem accessing the "index" member, so I suspect this is a bug in the type checker.
msg322043 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-07-21 00:19
> So I suspect this is a bug in the type checker.

Perhaps this report should go on the mypy bug tracker rather than the Python language tracker.
msg322045 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2018-07-21 00:26
> Perhaps this report should go on the mypy bug tracker rather than the Python language tracker.

Agreed. It's up to the OP to file an issue there though (hence adding @campkeith back to the nosy list).
msg322120 - (view) Author: Keith Campbell (campkeith) Date: 2018-07-21 18:58
> It's up to the OP to file an issue there though

Will do; thanks!
History
Date User Action Args
2022-04-11 14:59:03adminsetgithub: 78356
2018-07-21 18:58:56campkeithsetmessages: + msg322120
2018-07-21 00:26:59gvanrossumsetstatus: open -> closed

nosy: + campkeith
messages: + msg322045

resolution: third party
stage: resolved
2018-07-21 00:19:48rhettingersetnosy: + rhettinger, gvanrossum, levkivskyi, - campkeith
messages: + msg322043
2018-07-20 21:08:00campkeithcreate