Skip to content

Incorrect (or absent) error message for DefaultDict #2986

Closed
python/typeshed
#1456

Description

@ilevkivskyi

With this code:

from typing import DefaultDict
from collections import defaultdict

d: DefaultDict[str, int]
d[1] = 2

mypy shows a strange error (note "dict" instead of "DefaultDict"):

error: Invalid index type "int" for "dict"; expected type "str"

Moreover, if I remove the (redundant) import from collections, then mypy passes without errors.

Activity

  1. ilevkivskyi commented on Mar 10, 2017

    @ilevkivskyi
    MemberAuthor

    Since it looks like this bug was introduced by my old PR, I will fix this. You could assign this issue to me (I can't do this myself).

  2. self-assigned this
    on Mar 31, 2017
  3. ilevkivskyi commented on Apr 13, 2017

    @ilevkivskyi
    MemberAuthor

    This was partially fixed by #3147, now the error message correctly mentions defaultdict[str, int] instead of just dict. However, still the message disappears if redundant collections import is removed.

  4. ilevkivskyi commented on Jul 13, 2017

    @ilevkivskyi
    MemberAuthor

    This is now fixed by python/typeshed#1456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions