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

Use dict_factory in store for better readability #487

Merged
merged 23 commits into from
Jul 30, 2024
Merged

Conversation

Bouni
Copy link
Owner

@Bouni Bouni commented Jun 21, 2024

I always struggled with al those index numbers scatterd all around the code base and for a long time wanted to improve that.

So I started with the store and introduced a row_factory that returns a dict instead of a list which improves readability throughout the code base a lot.

For example

if self.hide_bom_parts and part[6]:

becomes

if self.hide_bom_parts and part["exclude_from_bom"]:

@Bouni Bouni requested a review from chmorgan June 21, 2024 12:16
@Bouni Bouni force-pushed the store-dict-factory branch from 688a4e9 to 25d27f1 Compare July 19, 2024 14:16
Copy link
Collaborator

@chmorgan chmorgan left a comment

Choose a reason for hiding this comment

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

A handful of minor comments, this is a huge cleanup. I like the idea of using the columns directly from the database to generate the dict, that way if the order does ever change none of the code will have to.

store.py Show resolved Hide resolved
store.py Outdated Show resolved Hide resolved
store.py Show resolved Hide resolved
@@ -779,7 +779,7 @@ def toggle_bom_pos(self, *_):
fp = board.FindFootprintByReference(ref)
bom = toggle_exclude_from_bom(fp)
pos = toggle_exclude_from_pos(fp)
self.store.set_bom(ref, bom)
self.store.set_bom(ref, int(bom))
Copy link
Collaborator

Choose a reason for hiding this comment

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

what was up with the necessity to cast here but not previously? (No mention in the commit message of the reason why)

Copy link
Owner Author

Choose a reason for hiding this comment

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

I don't remember but I guess that sqlite doesn't like to get a "1" for a boolean value. Previously the casting was done in th e set_bom function, in other places it was done like this. So I decided to make the cast always in the same place.

store.py Outdated Show resolved Hide resolved
@Bouni Bouni force-pushed the store-dict-factory branch from b904539 to cd001af Compare July 30, 2024 10:48
@Bouni Bouni requested a review from chmorgan July 30, 2024 10:50
@Bouni
Copy link
Owner Author

Bouni commented Jul 30, 2024

Thanks @chmorgan for the review 👍🏽

@Bouni Bouni merged commit 98f678f into main Jul 30, 2024
2 checks passed
@Bouni Bouni deleted the store-dict-factory branch September 30, 2024 08:24
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

Successfully merging this pull request may close these issues.

2 participants