-
Notifications
You must be signed in to change notification settings - Fork 222
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
Refactor: use Literals
in type hints
#1680
base: main
Are you sure you want to change the base?
Conversation
We need you to comply with our contributing guidelines and signoff the commits. https://github.com/docarray/docarray/blob/main/CONTRIBUTING.md |
@JoanFM I have signed the commits. Could you have a look at it? |
THE CI is complaining about that, as well as mypy, black and ruff |
Well how do I proceed with. Any leads appreciated. |
docarray/store/helpers.py
Outdated
@@ -131,12 +132,27 @@ def close(self): | |||
|
|||
|
|||
def _to_binary_stream( | |||
self, protocol: Literal['pickle', 'protobuf'], |
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.
default value should still be protobuf
here and we should not change the order of the argument (protocol should stay at the same place as before)
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 would want to make it clear if the protocol
is in the right place and order (i.e. 2nd argument).
Is my understanding correct? At the same time let me make sure to add protobuf
as the default value.
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.
Also, if we want protocol
to act as a default argument then it has to be placed at the end.
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 you can do what you did on the other and kept it at the end
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.
Thanks for you contribution ! Indeed litteral makes more sense in most of the case.
Two overall comments:
- Lets keep default value
- If possible we should not change the order of the parameters of existing function
docarray/store/helpers.py
Outdated
@@ -167,13 +183,28 @@ def _to_binary_stream( | |||
|
|||
|
|||
def _from_binary_stream( | |||
self, protocol: Literal['pickle', 'protobuf'], |
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 we can do like you id in the other
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.
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.
@samsja Can you have a look at this? Meanwhile let me work on the function implementation.
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.
It starts to look very good.
One idea, maybe we could wrap the Literal['protobuf','pickle']
into a more formal type that we could call each time instead or repeating it ?
Something like this:
Protocols = Literal['pickle','protobuf']
def my_func(protocol: Protocol):
...
Wdyt ?
It increases the modularity of the code and may be easier to maintain as well, what do you say? |
then lets do it |
Hey @samsja!
|
@srini047 can you install the pre commit hook and apply black, ruff and mypy for the CI to pass ! |
Signed-off-by: srini047 <srinikethcr7@gmail.com>
Signed-off-by: srini047 <srinikethcr7@gmail.com>
Signed-off-by: Joan Fontanals Martinez <joan.martinez@jina.ai> Signed-off-by: srini047 <srinikethcr7@gmail.com>
Signed-off-by: Joan Fontanals Martinez <joan.martinez@jina.ai> Signed-off-by: srini047 <srinikethcr7@gmail.com>
build(JoanFM): release 0.35.0 Signed-off-by: srini047 <srinikethcr7@gmail.com>
Signed-off-by: srini047 <srinikethcr7@gmail.com>
Signed-off-by: srini047 <srinikethcr7@gmail.com>
92d3b4f
to
661686f
Compare
Signed-off-by: Sriniketh J <81156510+srini047@users.noreply.github.com>
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1680 +/- ##
===========================================
- Coverage 85.55% 63.18% -22.37%
===========================================
Files 133 133
Lines 8585 8598 +13
===========================================
- Hits 7345 5433 -1912
- Misses 1240 3165 +1925
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
Fixes: #1670
protocol
withLiterals
and options being ['pickle', 'protobuf']