-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Parse json data from token if object is dict-like. #285
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #285 +/- ##
==========================================
- Coverage 94.00% 93.97% -0.04%
==========================================
Files 26 26
Lines 3020 3035 +15
Branches 636 640 +4
==========================================
+ Hits 2839 2852 +13
- Misses 88 90 +2
Partials 93 93
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
That commit looks good! |
@AngellusMortis I just pushed a fix for that; please give it a try! Pydantic is a more-special-than-usual case within cyclopts; as it's the only type that cyclopts practically disables it's own coercion engine for. |
that was a lightning fast reply! |
Watching a show right now. So Github is up and just automatically updating for me. lol. |
I'd appreciate it if you'd keep playing with it and let me know if you discover any other issues. Otherwise tonight/this weekend I'll be adding tests/docs for this new feature! Thanks! |
Find an issue: If you have aliases for your pydantic class, it does not accept the fields from the alias value. i.e. If you have a config that converts camelCase to snake_case: class BaseK8sModel(BaseModel):
"""Base model for k8s spec."""
model_config = ConfigDict(
alias_generator=to_camel,
populate_by_name=True,
from_attributes=True,
) It cannot load the values from camelCase, only snake_case. I did confirm that passing both the ENV and one of the nested properties via an option still works. |
I'll look into this, thanks! |
@BrianPugh Can you rebase this branch off of |
rebased! I still want to rethink this a little more; because as of right now it sort of bypasses a lot of Cyclopts mechanisms. It probably works well for most general use-cases (once I investigate the pydantic issue you brought up), but would like it to work for even those advanced use-cases. |
If an object is dict/dataclass-like, attempts to parse input data as a json-string.
@AngellusMortis can you play around with this and see if it satisfies your needs? I need to flesh out the rest of the PR and think a little harder if this is the appropriate mechanism, but it naively seems to work.
Addresses #282.
TODO