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

Stravalib 2.0 -> Introduce custom Pydantic types for field conversions #500

Open
3 tasks
jsamoocha opened this issue May 11, 2024 · 3 comments
Open
3 tasks

Comments

@jsamoocha
Copy link
Collaborator

  • Introduce custom types that inherit from the generated model's base types and add accessor logic to get the (Pint) Quantity representation of these base types.
  • Introduce custom type for time zones
  • Introduce custom type for time delta

Depends on #498

@lwasser
Copy link
Collaborator

lwasser commented May 11, 2024

this i think answers my question from the review about what the plan is.

@jsamoocha
Copy link
Collaborator Author

Yes, the plan is to access the "extended" attributes as follows:

d = some_object.distance  # returns float
q = some_object.distance.quantity  # returns pint.Quantity (in meters)
z = unithelper.feet(some_object.distance)  # returns pint.Quantity (in feet)

I found a way to achieve this and maintain a correct type hierarchy.

@lwasser
Copy link
Collaborator

lwasser commented May 12, 2024

@jsamoocha this sounds great.

i have a very basic question. The extender approach sounds like a smooth way to implement these conversions. I"m curious how this compares to returning the distance in quantities via a validator for each attr that forces the conversion when the model is populated. I have a few guesses as to why the extender is better but wanted to get your feedback!

  • perhaps involving typing and type overrides or
  • perhaps it would make the overall code base more complex having so many validators?
  • Or finally perhaps it allows other users who may want to raw response values to convert as they please + the quantity conversions that are so nice to have in place.

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

No branches or pull requests

2 participants