Skip to content

Conversation

DanieleMorotti
Copy link
Contributor

I fixed the type annotations errors for pydantic objects in some examples as noted in #490 .

When running make lint the following error occurs "UP007 Use X | Y for type annotations". If you know how to ignore it I will be happy to edit the pull request, thanks.

Copy link
Collaborator

@rm-openai rm-openai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually you can just do from __future__ import annotations and these type errors will go away on 3.9

@DanieleMorotti
Copy link
Contributor Author

Yes, I thought that was the solution, but it doesn't work when using | within a pydantic BaseModel class, maybe due to how Pydantic works.

For example, I got the following error:

TypeError: Unable to evaluate type annotation 'str | None'. If you are making use of the new typing syntax (unions using `|` since Python 3.10 or builtins subscripting since Python 3.9), you should either replace the use of new syntax with the existing `typing` constructs or install the `eval_type_backport` package.

Let me know if I'm wrong and I have to change the pull request.

rm-openai
rm-openai previously approved these changes Apr 14, 2025
@rm-openai
Copy link
Collaborator

cool - can you fix lint please?

@rm-openai
Copy link
Collaborator

oh wait lint is complaining about the exact thing i talked about hmm

@rm-openai
Copy link
Collaborator

I think you can do what it says and add https://pypi.org/project/eval-type-backport/, based on pydantic/pydantic#7873

@DanieleMorotti
Copy link
Contributor Author

I added the library to the dependencies as suggested, it should work now, tests passed

@rm-openai rm-openai merged commit e8f14da into openai:main Apr 14, 2025
5 checks passed
@DanieleMorotti DanieleMorotti deleted the fix_type_annotations_example branch April 24, 2025 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants