Failed to import: `Field` default cannot be set in `Annotated` for 'num_Annotated[str, FieldInfo(min_length=1, extra={})]'
See original GitHub issueError message:
Traceback (most recent call last):
File "/data/cuih7/[REDACTED]", line 7, in <module>
import inflect
File "/data/cuih7/miniconda3/envs/nlp20220817/lib/python3.10/site-packages/inflect/__init__.py", line 2046, in <module>
class engine:
File "/data/cuih7/miniconda3/envs/nlp20220817/lib/python3.10/site-packages/inflect/__init__.py", line 3781, in engine
def number_to_words( # noqa: C901
File "pydantic/decorator.py", line 36, in pydantic.decorator.validate_arguments.validate
import sys
File "pydantic/decorator.py", line 126, in pydantic.decorator.ValidatedFunction.__init__
try:
File "pydantic/decorator.py", line 259, in pydantic.decorator.ValidatedFunction.create_model
return fun
File "pydantic/main.py", line 972, in pydantic.main.create_model
File "pydantic/main.py", line 204, in pydantic.main.ModelMetaclass.__new__
File "pydantic/fields.py", line 488, in pydantic.fields.ModelField.infer
File "pydantic/fields.py", line 419, in pydantic.fields.ModelField.__init__
File "pydantic/fields.py", line 534, in pydantic.fields.ModelField.prepare
File "pydantic/fields.py", line 633, in pydantic.fields.ModelField._type_analysis
File "pydantic/fields.py", line 776, in pydantic.fields.ModelField._create_sub_type
File "pydantic/fields.py", line 451, in pydantic.fields.ModelField._get_field_info
ValueError: `Field` default cannot be set in `Annotated` for 'num_Annotated[str, FieldInfo(min_length=1, extra={})]'
I’m using the library from conda-forge. Downgrading from 6.0.0-pyhd8ed1ab_0
to 5.6.2-pyhd8ed1ab_0
fixes the issue.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
ValueError: `Field` default cannot be set in `Annotated` for ...
Failed to import: Field default cannot be set in Annotated for 'num_Annotated[str, FieldInfo(min_length=1, extra={})]' jaraco/inflect#169.
Read more >pydantic setting a default value for an annotated type
I've been running into an issue where I am trying to set a default value. The basic idea is that there is a...
Read more >Pydantic only fields - ormar
If ormar cannot resolve the value for pydantic field it will fail during ... If you set a field as Optional , it...
Read more >Postponed annotations - pydantic
Both postponed annotations via the future import and ForwardRef require Python 3.7+. Postponed annotations (as described in PEP563) "just work".
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks, I think the issue is mostly clarified. Either need to update
pydantic
to above 1.9 (maybe below 1.9 works too?) or downgradeinflect
to e.g. 5.6. I useconda
and unfortunately it let’s me update only topydantic
1.9, but let’s me downgradeinflect
to 5.3, and everything seems to work fine then. Good enough for me.In fact, tests pass on pydantic 1.9.1.