Find answers from the community

Updated 9 months ago

Pydantic question!

At a glance

The community member is using the Llama Index library, which uses a try/except strategy when importing pydantic.v1 vs pydantic. This causes issues with pyright's type checking, as it is unable to statically determine which version of pydantic is being used. The community member is looking for an "eloquent solution" to this problem, which forces them to add # type:ignore comments.

In the comments, another community member asks if the issue is with the import in the community member's own code or just in general. Another community member suggests using the v1 import directly if it's in the community member's own code. However, for the general case, the other community member is not sure of a solution, but mentions that removing v1 support (which will likely happen in a few months) could be a potential solution.

Useful resources
Pydantic question!

Llama Index uses a try/except strategy when importing pydantic.v1 vs pydantic as seen in
https://github.com/run-llama/llama_index/blob/main/llama-index-core/llama_index/core/bridge/pydantic.py

This makes pyright's type checking unhappy. I presume it's unable to statically determine which pydantic is used (because the import is essentially dynamic) and complains, forcing us to add the dreaded # type:ignore comment to anything that touches this pydantic bridge.

Has anyone found an eloquent solution for this?
L
3 comments
Are you important from the bridge in your code, or you just mean in general?
If its an import in your code, I would use the v1 import directly
Otherwise, not sure I have a solution for that πŸ˜… Besides removing v1 support (which will probably happen in a few months hopefully)
Add a reply
Sign up and join the conversation on Discord