Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytype cannot recognize a List[TypedDict] of more than 63 elements #1484

Open
qxcv opened this issue Aug 7, 2023 · 2 comments
Open

pytype cannot recognize a List[TypedDict] of more than 63 elements #1484

qxcv opened this issue Aug 7, 2023 · 2 comments
Labels
bug cat: generics Generic, TypeVar, containers

Comments

@qxcv
Copy link

qxcv commented Aug 7, 2023

I have a list of dicts annotated with as List[T] where T is a TypedDict. I've found that pytype complains when it has more than 63 elements. Here's a working example (pytype_fail.py):

from typing import List, TypedDict

class T(TypedDict):
    a: str

list63: List[T] = [
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
]
list64: List[T] = [
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
    {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'}, {'a': 'a'},
]

Expected pytype output: type checks pass, everything is okay.

Actual output with 2023.07.28: fails on the list64 declaration (but not the list63 declaration) with this error:

Computing dependencies
Analyzing 1 sources with 0 local dependencies
ninja: Entering directory `.pytype'
[1/1] check pytype_fail
FAILED: /.../.pytype/pyi/pytype_fail.pyi 
/.../python -m pytype.single --imports_info /.../.pytype/imports/pytype_fail.imports --module-name pytype_fail --platform linux -V 3.10 -o /.../.pytype/pyi/pytype_fail.pyi --analyze-annotated --enable-cached-property --nofail --quick /.../pytype_fail.py
File "/.../pytype_fail.py", line 16, in <module>: Type annotation for list64 does not match type of assignment [annotation-type-mismatch]
  Annotation: List[T]
  Assignment: List[Dict[str, str]]
  
  TypedDict missing keys: a

For more details, see https://google.github.io/pytype/errors.html#annotation-type-mismatch
ninja: build stopped: subcommand failed.
Leaving directory '.pytype'
@rchen152 rchen152 added bug cat: generics Generic, TypeVar, containers labels Aug 23, 2023
@wyattscarpenter
Copy link
Contributor

I've also found that it complains with a dict of TypedDicts of more than 63 elements.

@wyattscarpenter
Copy link
Contributor

Ah, this is just #1545

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cat: generics Generic, TypeVar, containers
Projects
None yet
Development

No branches or pull requests

3 participants