Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update the return type of methods #676

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

Merged
merged 4 commits into from
Feb 13, 2023
Merged

Update the return type of methods #676

merged 4 commits into from
Feb 13, 2023

Conversation

sanders41
Copy link
Collaborator

@sanders41 sanders41 commented Feb 5, 2023

Pull Request

Related issue

Fixes #610
Potentially fixes #449

What does this PR do?

  • Updates the return types for methods
  • Some of the methods listed in the issue don't return TaskInfo but I went ahead and updated them anyways because they are part of Add more precise typing #449

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

@sanders41 sanders41 added the breaking-change The related changes are breaking for the users label Feb 5, 2023
Copy link
Contributor

@alallema alallema left a comment

Choose a reason for hiding this comment

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

Thank you so much @sanders41 for this PR ❤️, it's a huge job! 🔥 🔥 🔥
and I'm really happy to see it done 😄
I have added some comments

Copy link
Contributor

@alallema alallema left a comment

Choose a reason for hiding this comment

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

Last question!

Comment on lines +29 to +42
class KeyUpdate(CamelBase):
key: str
name: Optional[str] = None
description: Optional[str] = None
actions: Optional[List[str]] = None
indexes: Optional[List[str]] = None
expires_at: Optional[datetime] = None

class Config:
json_encoders = {
datetime: lambda v: None
if not v
else f"{str(v).split('.', maxsplit=1)[0].replace(' ', 'T')}Z"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly this class is only used for the return of the update_key method so why not use it directly Key? We can keep this class to provide a Class to update Key like:

class KeyUpdate(CamelBase):
    name: str = None
    description: str = None

def update_key(self, key_or_uid: str, options: KeyUpdate) -> Key:

But I'm not sure it's worth it. WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a mistake, I should have used Key for the return. What I use KeyUpdate for is exactly what you described. The disadvantage is the user has to import KeyUpdate, but the advantage is the user knows exactly what to send.

I think an argument could be made for both options. I'll let you make the call if you want me to change options to KeyUpdate, or if you want me to remove the class.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a strong opinion on this. I tend to agree with you, I find it easier for the user to keep the option. The only advantage of using a KeyUpdate is that there is no risk of making a mistake on how to update the key due to the Strong guidance.
Let's leave it as it is I think it's fine

Copy link
Contributor

@alallema alallema left a comment

Choose a reason for hiding this comment

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

Thank you so much @sanders41 this is perfect! 🔥 🔥 🔥
LGTM! ✨

Comment on lines +29 to +42
class KeyUpdate(CamelBase):
key: str
name: Optional[str] = None
description: Optional[str] = None
actions: Optional[List[str]] = None
indexes: Optional[List[str]] = None
expires_at: Optional[datetime] = None

class Config:
json_encoders = {
datetime: lambda v: None
if not v
else f"{str(v).split('.', maxsplit=1)[0].replace(' ', 'T')}Z"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a strong opinion on this. I tend to agree with you, I find it easier for the user to keep the option. The only advantage of using a KeyUpdate is that there is no risk of making a mistake on how to update the key due to the Strong guidance.
Let's leave it as it is I think it's fine

@alallema
Copy link
Contributor

bors merge

@bors
Copy link
Contributor

bors bot commented Feb 13, 2023

@bors bors bot merged commit 2f587cb into main Feb 13, 2023
@bors bors bot deleted the return-type branch February 13, 2023 11:20
bors bot added a commit that referenced this pull request Feb 22, 2023
693: Update version for the next release (v0.25.0) r=alallema a=alallema

## ⚠️ Breaking changes

* Update the return type of methods (#676) `@sanders41`

## 🚀 Enhancements

* Transform all the `task` methods to a `TaskHandler` class (#662) `@Azanul`

Thanks again to `@Azanul,` `@alallema,` `@brunoocasali` and `@sanders41!` 🎉


Co-authored-by: alallema <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change The related changes are breaking for the users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update the return of methods that should return TaskInfo Add more precise typing
2 participants