-
Notifications
You must be signed in to change notification settings - Fork 73
♻️ Store needs as NeedItem
/ NeedPartItem
, rather than standard dict
#1485
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
NeedItem
, rather than standard dictNeedItem
/ NeedPartItem
, rather than standard dict
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1485 +/- ##
==========================================
+ Coverage 86.87% 88.74% +1.86%
==========================================
Files 56 68 +12
Lines 6532 8473 +1941
==========================================
+ Hits 5675 7519 +1844
- Misses 857 954 +97
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
NeedItem
/ NeedPartItem
, rather than standard dictNeedItem
/ NeedPartItem
, rather than standard dict
Currently, need data items are stored as standard Python dicts, which is also exposed to the user in various APIs This is problematic as it does not allow for (a) any internal checks to ensure data is updated consistently (e.g. fields like `id` should never be changed), (b) it does not allow any data to be "hid" from the user, or presented in a different way to its internal structure. In this PR, we instead add a specific `NeedItem` class, which closely mimics a dictionary, but also allows for additional functionality. We also introduce a `NeedPartItem` which is distinctly different from a `NeedItem`, e.g. it should not be mutated.
f73cfec
to
f3a92e8
Compare
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.
This looks good to me and is a required step to get people to use the API or complain if something is missing. We should inform core users about this change.
I just have 2 comments, please decide whether those are issues right now or not.
self, | ||
key: Literal[ | ||
"id", | ||
"id_parent", |
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.
id_parent should be optional, it's about need part parent - would it break the data model to change it to str | None
?
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.
This particular PR is not intended to change any schema specifics; e.g. it shows that this change does not change any output needs.json
So it may well be a legitimate change, but should not be made here
"external_css", | ||
"constraints_error", | ||
"section_name", | ||
"parent_need", |
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.
same here, parent_need
is optional, it's about need nesting. Wouldn't str | None
be better?
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.
Same as above
Currently, need data items are stored as standard Python dicts, which is also exposed to the user in various APIs and as the
needs.json
.This is problematic as it does not allow for
id
should never be changed),In this PR, we instead add a specific
NeedItem
class, which closely mimics adict
, but also allows for additional constraints and functionality.We also introduce a
NeedPartItem
which is distinctly different from aNeedItem
, e.g. it should not be mutated.To ensure that no existing user code is accidentally breaking this, e.g. by directly add dictionaries to the list of needs,
we perform a check, at the end of the post-processing stage, to make sure all need items are instances of
NeedItem
(and point them towards the "correct"
add_need
API)This would be breaking for any users doing "non-API" modifications / additions to the needs data, i.e. directly adding dict items.
It should not change interactions with standard APIs like
add_need
or filter strings, etc