Skip to content

typing.Counter is not supported #2060

@vhsw

Description

@vhsw

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.7
            pydantic compiled: True
                 install path: /home/user/app/.venv/lib/python3.8/site-packages/pydantic
               python version: 3.8.6 (default, Sep 25 2020, 09:36:53)  [GCC 10.2.0]
                     platform: Linux-5.9.0-1-amd64-x86_64-with-glibc2.29
     optional deps. installed: ['typing-extensions']

Minimal example:

from typing import Counter
from pydantic import BaseModel
class ProcessedDoc(BaseModel):
    named_entities: Counter[str]

Result:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pydantic/main.py", line 262, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 315, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 284, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 356, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 492, in pydantic.fields.ModelField._type_analysis
IndexError: tuple index out of range

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions