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 does not recognize properly Sequence and Iterable collection when their size is larger than 63. #1545

Open
Frang84 opened this issue Dec 13, 2023 · 1 comment
Labels
bug cat: generics Generic, TypeVar, containers

Comments

@Frang84
Copy link

Frang84 commented Dec 13, 2023

from typing import List, TypedDict, Sequence, Iterable, Callable 

class T(TypedDict):
    a: str

sequence63: Iterable[T] = [
    {'a': 'bocian'}, {'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'},
]


"""
sequence64: Iterable[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'},
]"""

OUTPUT:
Type annotation for sequence64 does not match type of assignment [annotation-type-mismatch]
Annotation: Iterable[T]
Assignment: List[Dict[str, str]]

TypedDict missing keys: a

from typing import List, TypedDict, Sequence, Iterable, Callable 

class T(TypedDict):
    a: str

sequence63: Sequence[T] = [
    {'a': 'bocian'}, {'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'},
]


"""
sequence64: Sequence[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'},
]"""

OUTPUT:
Type annotation for sequence64 does not match type of assignment [annotation-type-mismatch]
Annotation: Sequence[T]
Assignment: List[Dict[str, str]]

TypedDict missing keys: a

@Frang84 Frang84 changed the title Pytype doePytype does not recognize properly Sequence and Iterable collection when their size is larger than 63. Pytype, in both scenarios, recognizes type as List[Dict[str, str]], which is incorrect.s not recognize Pytype doePytype does not recognize properly Sequence and Iterable collection when their size is larger than 63. Dec 13, 2023
@rchen152 rchen152 changed the title Pytype doePytype does not recognize properly Sequence and Iterable collection when their size is larger than 63. Pytype does not recognize properly Sequence and Iterable collection when their size is larger than 63. Dec 14, 2023
@rchen152 rchen152 added bug cat: generics Generic, TypeVar, containers labels Dec 14, 2023
@rchen152
Copy link
Contributor

I suspect this is happening because of the MAX_VAR_SIZE cutoff here:

MAX_VAR_SIZE = 64
.
For now, you can just disable the error; pytype will still apply the type annotation despite it.

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

2 participants