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

typing.Counter is not supported #2060

Closed
3 tasks done
vhsw opened this issue Oct 28, 2020 · 1 comment · Fixed by #2806
Closed
3 tasks done

typing.Counter is not supported #2060

vhsw opened this issue Oct 28, 2020 · 1 comment · Fixed by #2806

Comments

@vhsw
Copy link

vhsw commented Oct 28, 2020

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
@vhsw vhsw added the bug V1 Bug related to Pydantic V1.X label Oct 28, 2020
@samuelcolvin samuelcolvin added feature request and removed bug V1 Bug related to Pydantic V1.X labels Oct 28, 2020
@samuelcolvin
Copy link
Member

this is not a bug but a feature request.

apiology added a commit to apiology/microCOVID that referenced this issue May 22, 2022
Resolves issue found when using improved type annotations.

Looks like this may be the cause: pydantic/pydantic#2060

$ ./update_prevalence.py
Traceback (most recent call last):
  File "/Users/broz/src/microCOVID/./update_prevalence.py", line 367, in <module>
    class Place(pydantic.BaseModel):
  File "/Users/broz/src/microCOVID/.venv/lib/python3.10/site-packages/pydantic/main.py", line 299, in __new__
    fields[ann_name] = ModelField.infer(
  File "/Users/broz/src/microCOVID/.venv/lib/python3.10/site-packages/pydantic/fields.py", line 411, in infer
    return cls(
  File "/Users/broz/src/microCOVID/.venv/lib/python3.10/site-packages/pydantic/fields.py", line 342, in __init__
    self.prepare()
  File "/Users/broz/src/microCOVID/.venv/lib/python3.10/site-packages/pydantic/fields.py", line 451, in prepare
    self._type_analysis()
  File "/Users/broz/src/microCOVID/.venv/lib/python3.10/site-packages/pydantic/fields.py", line 604, in _type_analysis
    self.type_ = get_args(self.type_)[1]
IndexError: tuple index out of range
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants