Closed cuihaoleo closed 1 year ago
For me, tests are passing, so there must be something unique to your environment that's incompatible. Perhaps you have an older, incompatible version of pydantic, which was introduced in version 6.
Had the same issue. I installed the latest version of inflect
(6.0.0). After receiving an error about pydantic
"Field
", I figured my pydantic
version was old (0.18) and didn't have Field
yet, so upgraded to latest pydantic
(1.9.0 on conda). But this time I started getting the above error.
I found this on pydantic
site: pydantic issues: 3991, which implies that this is expected behavior on pydantic side, so needs to be fixed on inflect side. Hope this contributes a bit to the solution.
What I don't understand is why don't I encounter the error and why doesn't the error occur in the CI tests?
~ $ pip-run inflect -- -c 'import inflect'; echo done
Collecting inflect
Using cached inflect-6.0.1-py3-none-any.whl (34 kB)
Collecting pydantic
Using cached pydantic-1.10.2-cp310-cp310-macosx_11_0_arm64.whl (2.6 MB)
Collecting typing-extensions>=4.1.0
Using cached typing_extensions-4.4.0-py3-none-any.whl (26 kB)
Installing collected packages: typing-extensions, pydantic, inflect
Successfully installed inflect-6.0.1 pydantic-1.10.2 typing-extensions-4.4.0
done
It's difficult for me to fix if I can't replicate the error. It's obviously not strictly a pydantic issue. There's another factor.
Oh. That's interesting - pinning to pydantic 1.9, I can replicate the error:
~ $ pip-run inflect 'pydantic==1.9' -- -c 'import inflect'; echo done
Collecting inflect
Using cached inflect-6.0.1-py3-none-any.whl (34 kB)
Collecting pydantic==1.9
Downloading pydantic-1.9.0-cp310-cp310-macosx_11_0_arm64.whl (2.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.4/2.4 MB 19.7 MB/s eta 0:00:00
Collecting typing-extensions>=3.7.4.3
Using cached typing_extensions-4.4.0-py3-none-any.whl (26 kB)
Installing collected packages: typing-extensions, pydantic, inflect
Successfully installed inflect-6.0.1 pydantic-1.9.0 typing-extensions-4.4.0
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/var/folders/sx/n5gkrgfx6zd91ymxr2sr9wvw00n8zm/T/pip-run-rtp61g6y/inflect/__init__.py", line 2054, in <module>
class engine:
File "/var/folders/sx/n5gkrgfx6zd91ymxr2sr9wvw00n8zm/T/pip-run-rtp61g6y/inflect/__init__.py", line 3791, in engine
def number_to_words( # noqa: C901
File "pydantic/decorator.py", line 36, in pydantic.decorator.validate_arguments.validate
File "pydantic/decorator.py", line 126, in pydantic.decorator.ValidatedFunction.__init__
File "pydantic/decorator.py", line 259, in pydantic.decorator.ValidatedFunction.create_model
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={})]'
done
I also can get tests in CI to fail with pydantic 1.9.
Maybe the solution is simply to apply a minimum bound on pydantic to 1.10.
In fact, tests pass on pydantic 1.9.1.
Thanks, I think the issue is mostly clarified. Either need to update pydantic
to above 1.9 (maybe below 1.9 works too?) or downgrade inflect
to e.g. 5.6.
I use conda
and unfortunately it let's me update only to pydantic
1.9, but let's me downgrade inflect
to 5.3, and everything seems to work fine then. Good enough for me.
Looks like a pydantic bug introduced in 1.9. Fixed in 1.9.1.
Fix in-place modification of FieldInfo that caused problems with PEP 593 type aliases, https://github.com/pydantic/pydantic/pull/4067 by @adriangb
I guess things are clear. Thanks for the tests! Feel free to close this issue.
I confirmed that commit makes the difference:
Thanks everyone for the patience and understanding.
Error message:
I'm using the library from conda-forge. Downgrading from
6.0.0-pyhd8ed1ab_0
to5.6.2-pyhd8ed1ab_0
fixes the issue.