-
Notifications
You must be signed in to change notification settings - Fork 122
Add defaults to all the Item.from_dict
pops
#994
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
Conversation
Just noticed the comment on the other PR about pytest. I'll update this now |
Codecov ReportBase: 90.13% // Head: 90.13% // No change to project coverage 👍
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## main #994 +/- ##
=======================================
Coverage 90.13% 90.13%
=======================================
Files 47 47
Lines 6164 6164
Branches 920 923 +3
=======================================
Hits 5556 5556
Misses 426 426
Partials 182 182
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
I'm going to link this with #831, even though it doesn't implement the fix exactly as recommended by @philvarner. IMO we don't want to doing psuedo-validation in multiple places, so if there is going to be validity checks, they should probably be in the constructor (not in |
Pete, I think you're getting to root of one of the issues with methods like this, that take an arbitrary input and produce a constrained/validated object. If I were going to (possibly-over) design this:
|
@philvarner I don't think the current code is that far from what you're describing. The I'm not sure of the value of class MaybeItem:
type: Optional[Any]
stac_version: Optional[Any]
... Am I misunderstanding |
I was thinking of it a bit more strict than that -- the fields value are all Optional, but of the correct type. class MaybeItem: The use case here is the same one that Item is currently failing on -- I want to read an invalid item and then presumably do something with it while in an invalid state or modify it to be valid. When I'm modifying it, it's a nicer experience to modify the object and get the typechecking on it rather than operating on an dict[str, Any] with no checking. |
Fair, and makes sense. There is a tradeoff w/ complexity b/c we'd be adding another, slightly ambiguous item to the namespace. I do see the value in providing some sort of support for invalid STAC -- without it, we end up with problems like #991, where it's totally opaque to a user what the problem is w/ a STAC read operation. My instinct is to try to ring-fence the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
several comments.
Raises more sensible errors if required fields are missing, used to be KeyErrors
e6c2238
to
dfde1be
Compare
Related Issue(s): #831
Description:
The easy solution to better error handling is to just defer until the init. So I added pop defaults to all the dict fields even if they are required
PR Checklist:
pre-commit run --all-files
)scripts/test
)