Skip to content

pytype errors on type hinted generics #1114

@GBeauregard

Description

@GBeauregard

The following is valid for type hinting (taken directly from https://www.python.org/dev/peps/pep-0585/ ), but fails to type check.

l = list[str]()

actual behavior:

[1/1] check testnew
FAILED: /home/gregory/Downloads/testcase/pytest/.pytype/pyi/testnew.pyi
/home/gregory/.venvs/pyffstream/bin/python -m pytype.single --imports_info /home/gregory/Downloads/testcase/pytest/.pytype/imports/testnew.imports --module-name testnew -V 3.9 -o /home/gregory/Downloads/testcase/pytest/.pytype/pyi/testnew.pyi --analyze-annotated --nofail --quick /home/gregory/Downloads/testcase/pytest/testnew.py
File "/home/gregory/Downloads/testcase/pytest/testnew.py", line 1, in <module>: 'list' object is not callable [not-callable]

Expected: l is determined to have type list[str] while being initialized to [].

This is discouraged for types with built in literal syntax (like [] for list()), but it is nevertheless valid. Moreover, one probably can still make use of this syntax with set().

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions