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

Import typeddict from typing_extentions #104

Merged
merged 6 commits into from
Dec 20, 2023

Conversation

eavanvalkenburg
Copy link
Contributor

@eavanvalkenburg eavanvalkenburg commented Dec 12, 2023

Description of the change

When using classes from the types with Pydantic [as mentioned here],(https://docs.pydantic.dev/2.1/usage/types/dicts_mapping/#typeddict) Pydantic throws an error that typeddict needs to come from typing_extentions for python < 3.11, hence this PR.

Motivation

Allows this packages classes to be used within pydantic based classes.

Type of change

Choose one: Bug Fix for #102

Checklist

  • I have performed a self-review of my code.
  • I have added detailed comments to my code where applicable.
  • I have verified that my change does not break existing code.
  • My PR is based on the latest changes of the main branch (if unsure, please run git pull --rebase upstream main).
  • I am familiar with the Google Style Guide for the language I have coded in.
  • I have read through the Contributing Guide and signed the Contributor License Agreement.

@eavanvalkenburg eavanvalkenburg requested a review from a team as a code owner December 12, 2023 14:58
Copy link

google-cla bot commented Dec 12, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added status:awaiting review PR awaiting review from a maintainer component:python sdk Issue/PR related to Python SDK labels Dec 12, 2023
@markmcd
Copy link
Member

markmcd commented Dec 12, 2023

Do you have a link that explains why it's needed? The link you provided lists:

This is a new feature of the Python standard library as of Python 3.8. Prior to Python 3.8, it requires the typing-extensions package. But required and optional fields are properly differentiated only since Python 3.9. We therefore recommend using typing-extensions with Python 3.8 as well.

We only support 3.9+, so it sounds like it's already OK, but that obviously isn't your experience so I'd like to understand the problem better.

@eavanvalkenburg
Copy link
Contributor Author

@markmcd this is where they go into the details of this choice, I also do not like it, but would love to use the direct types in a pydantic class, hence this issue!

Copy link
Collaborator

@MarkDaoust MarkDaoust left a comment

Choose a reason for hiding this comment

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

This looks pretty reasonable.

The tests only pass because typing_extensions is indirectly pulled in by our [dev] install.

Before we merge this, we need to add typing-extensions to the requirements in setup.py.

Optional: use environment markers to make it a conditional requirement.

@MarkDaoust
Copy link
Collaborator

To keep things simple is there any downside to always importing from typing-extensions?

I think I'm going to start with that.

@MarkDaoust MarkDaoust merged commit 04dbd5f into google-gemini:main Dec 20, 2023
6 checks passed
@github-actions github-actions bot removed the status:awaiting review PR awaiting review from a maintainer label Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:python sdk Issue/PR related to Python SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants