-
Notifications
You must be signed in to change notification settings - Fork 164
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
Introduce the StoreItem base class #1158
base: master
Are you sure you want to change the base?
Conversation
- introduced a new class that implements common functionality for items in a BaseStore - added corresponding unit tests - fixed a typo in the copyright text
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.
I think it's a good improvement! Just some minor comments.
GTG/core/base_store.py
Outdated
def __init__(self,id: UUID): | ||
self.id: UUID = id | ||
self.parent: Optional[Self] = None | ||
self.children: List[Self] = [] |
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.
self.children: List[Self] = [] | |
self.children: list[Self] = [] |
Now that Python 3.8 is gone, we can write code that targets 3.9, which means we no longer need typing.List
and the like.
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.
Done. (We should also update the readme and every other reference to python version.)
GTG/core/base_store.py
Outdated
self.id: UUID = id | ||
self.parent: Optional[Self] = None | ||
self.children: List[Self] = [] | ||
super(StoreItem, self).__init__() |
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.
super(StoreItem, self).__init__() | |
super().__init__() |
Bad habits form Python 2 still in the code base :) Let's fix them as we see them.
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.
Done.
GTG/core/base_store.py
Outdated
return ancestors | ||
|
||
|
||
def check_possible_parent(self, target) -> bool: |
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.
def check_possible_parent(self, target) -> bool: | |
def is_parent_of(self, target) -> bool: |
and inverse the conditions below.
I think it might be clearer to read if not foo.is_parent_of(bar):
rather than if foo.check_possible_parent(bar):
?
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.
I agree that the name is not perfect. However, is_parent_of
wouldn't correctly describe the method (e.g., you can not parent an item to itself.) I used is_parentable_to
in the new version. I think it also reads much better than the original one.
tests/core/test_store_item.py
Outdated
self.assertFalse(item.has_children) | ||
|
||
|
||
def test_children_count_singel_child(self): |
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.
def test_children_count_singel_child(self): | |
def test_children_count_single_child(self): |
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.
Done.
- use Python 3.9 type hint - simplify super() calls - fix a typo in a test case - rename check_possible_parent to is_parentabel_to Co-authored-by: Kevin Guillaumond <[email protected]>
This is a followup to PR #1151 removing duplicated functionality. The main benefits include:
BaseStore
class (which I would be happy to do).The main changes are as follows:
BaseStore
,