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

Refactor: use Literals in type hints #1680

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

srini047
Copy link
Contributor

Fixes: #1670

  • I have made sure to protocol with Literals and options being ['pickle', 'protobuf']

@JoanFM
Copy link
Member

JoanFM commented Jun 28, 2023

We need you to comply with our contributing guidelines and signoff the commits.

https://github.com/docarray/docarray/blob/main/CONTRIBUTING.md

@srini047
Copy link
Contributor Author

srini047 commented Jun 29, 2023

@JoanFM I have signed the commits. Could you have a look at it?

image

@JoanFM
Copy link
Member

JoanFM commented Jun 29, 2023

@JoanFM I have signed the commits. Could you have a look at it?

image

THE CI is complaining about that, as well as mypy, black and ruff

@srini047
Copy link
Contributor Author

@JoanFM I have signed the commits. Could you have a look at it?
image

THE CI is complaining about that, as well as mypy, black and ruff

Well how do I proceed with. Any leads appreciated.
Thanks in advance!

@@ -131,12 +132,27 @@ def close(self):


def _to_binary_stream(
self, protocol: Literal['pickle', 'protobuf'],
Copy link
Member

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)

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

@samsja samsja left a 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

@@ -167,13 +183,28 @@ def _to_binary_stream(


def _from_binary_stream(
self, protocol: Literal['pickle', 'protobuf'],
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Facing this error When I try to commit the changes. Any help on the same appreciated.

Copy link
Contributor Author

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.

Copy link
Member

@samsja samsja left a 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 ?

@srini047
Copy link
Contributor Author

srini047 commented Jul 4, 2023

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?

@samsja
Copy link
Member

samsja commented Jul 4, 2023

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

@srini047
Copy link
Contributor Author

srini047 commented Jul 5, 2023

Hey @samsja!

  • Please have a look at the approach if this helps. Or else let me revert to any other logic
  • Also, I need help in docarray/store/helpers.py and I have tagged you in the issue I am facing.

@samsja
Copy link
Member

samsja commented Jul 14, 2023

@srini047 can you install the pre commit hook and apply black, ruff and mypy for the CI to pass !

srini047 and others added 7 commits July 21, 2023 22:47
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>
@srini047 srini047 force-pushed the refactor-literal-type-hints branch from 92d3b4f to 661686f Compare July 21, 2023 17:17
Signed-off-by: Sriniketh J <81156510+srini047@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Jul 21, 2023

Codecov Report

Patch coverage: 18.75% and project coverage change: -22.37 ⚠️

Comparison is base (304a4e9) 85.55% compared to head (b7664a4) 63.18%.

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     
Flag Coverage Δ
docarray 63.18% <18.75%> (-22.37%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
docarray/store/helpers.py 22.50% <14.28%> (-64.54%) ⬇️
docarray/base_doc/mixins/io.py 78.49% <50.00%> (-11.24%) ⬇️

... and 72 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

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.

Refactor: use Literal in type hints
4 participants