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

Python code cleanup #2573

Merged
merged 4 commits into from
Nov 7, 2024
Merged

Python code cleanup #2573

merged 4 commits into from
Nov 7, 2024

Conversation

prateek-kumar-improving
Copy link
Collaborator

@prateek-kumar-improving prateek-kumar-improving commented Nov 2, 2024

Issue link

This Pull Request is linked to issue (URL): #2429

PR description

This is a follow up PR based on a thorough review of the Python VSS module code to improve the code quality of the final code sent into the release. It includes the following changes:

Documentation fixes, test case refactoring and adding binary tests.

  1. Move all tests to common file. As suggested during one of the code reviews.
    Files removed: python/python/tests/tests_server_modules/search/test_ft_create.py,
    python/python/tests/tests_server_modules/search/test_ft_search.py,
    python/python/tests/tests_server_modules/search/test_ft_dropindex.py
    All tests moved to python/python/tests/tests_server_modules/test_ft.py
  2. Examples section in documentation - replace : with # in all commands 
  3. Remove all See statements like: See FtCreateOptions. This is not required here because unlike JAVA it does not link to anything. It is redundant code because the class name is present in params section the documentation and this is self explanatory.
  4. Add tests for TEncodable(binary data) for all commands. Added for some commands already, maybe 3-4 commands were missed.
  5. Python: Fix nit in this PR: FT.EXPLAIN and FT.EXPLAINCLI commands added #2508
  6. Remove docs for overloaded methods in VSS module wherever necessary. Example: https://github.com/valkey-io/valkey-glide/pull/2530/files#r1819482800

Typo fixes, variable names consistency fixes, function name consistency fixes:

  1. Typo in FtSearchOptions class name. Currently it is FtSeachOptions. Corrected the typo in the import statement and throughout the code by changing FtSeachOptions to FtSearchOptions in python/python/glide/__init__.py and python/python/glide/async_commands/server_modules/ft.py [1] [2] [3] [4].
  2. Fix variable names in test cases to be underscore. Based on an internal discussion. Renamed variables for consistency, changing indexName to index_name in multiple functions in python/python/glide/async_commands/server_modules/ft.py [1] [2] [3] [4] [5] [6] [7] [8] [9] [10].
  3. Change all function names to use underscore in Python. Example: Change toArgs() to to_args(). This is already done for FT.AGGREGATE. Fix for others. Updated method names from toArgs to to_args for consistency in python/python/glide/async_commands/server_modules/ft_options/ft_create_options.py [1] [2] [3] [4] [5] [6].
  4. Corrected a typo in class name FtSeachKeywords to FtSearchKeywords in python/python/glide/async_commands/server_modules/ft_options/ft_constants.py.
  5. Added a changelog entry for the Python code cleanup in CHANGELOG.md.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one issue.
  • Commit message has a detailed description of what changed and why.
  • Tests are added or updated.
  • CHANGELOG.md and documentation files are updated.
  • Destination branch is correct - main or release
  • Commits will be squashed upon merging.

Signed-off-by: Prateek Kumar <prateek.kumar@improving.com>
Signed-off-by: Prateek Kumar <prateek.kumar@improving.com>
Signed-off-by: Prateek Kumar <prateek.kumar@improving.com>
Signed-off-by: Prateek Kumar <prateek.kumar@improving.com>
schema (List[Field]): Fields to populate into the index. Equivalent to `SCHEMA` block in the module API.
options (Optional[FtCreateOptions]): Optional arguments for the FT.CREATE command. See `FtCreateOptions`.
options (Optional[FtCreateOptions]): Optional arguments for the FT.CREATE command.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you remove the see?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In case of python, unlike JAVA and Node, this statement does not link to the actual class and is therefore not adding any extra value.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to find a python doc validator and generator. This will define doc format and then we can restore all see to ensure links are properly rendered in HTML docs.

"""
args = super().toArgs()
def to_args(self) -> List[TEncodable]:
args = super().to_args()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why removing docs?
You can change to dev docs and leave something simple

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 is an inherited class, and the doc from the main abstract class for this method is available when we hover over the method in IDE. This is the feedback I got when I discussed with others about this.
This was first mentioned in this PR comment: https://github.com/valkey-io/valkey-glide/pull/2530/files#r1819482800

I can change this back, if you think for some reason we need this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If the docs in the abstract are sufficient, no need

+ ' incline! They may be at the age when a 27.5\\" wheel bike is just too clumsy'
+ ' coming off a 24\\" bike. The Hillcraft 26 is just the solution they need!",'
+ ' "condition": "used"}',
'{"brand": "Bicyk", "model": "Hillcraft", "price": 1200, "condition": "used"}',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Upon review of the code across all languages, I found this has already been removed from the JAVA integ tests, I want to keep everything consistent across languages.
The reason for removal from JAVA: It is a JSON key that is not used for anything during testing and is adding no value by keeping it in the record.

@avifenesh
Copy link
Collaborator

Issue link

This Pull Request is linked to issue (URL): #2429

Checklist

Before submitting the PR make sure the following are checked:

* [x]  This Pull Request is related to one issue.

* [x]  Commit message has a detailed description of what changed and why.

* [x]  Tests are added or updated.

* [x]  CHANGELOG.md and documentation files are updated.

* [x]  Destination branch is correct - main or release

* [x]  Commits will be squashed upon merging.

The issue doesn't mention the reasoning for this PR, can you elaborate on the goal and actions?

@avifenesh
Copy link
Collaborator

Issue link

This Pull Request is linked to issue (URL): #2429

Checklist

Before submitting the PR make sure the following are checked:

* [x]  This Pull Request is related to one issue.

* [x]  Commit message has a detailed description of what changed and why.

* [x]  Tests are added or updated.

* [x]  CHANGELOG.md and documentation files are updated.

* [x]  Destination branch is correct - main or release

* [x]  Commits will be squashed upon merging.

Lazy blueprint for elaborating, you can edit with the real details:

This pull request focuses on code cleanup and consistency improvements in the Python codebase, specifically for the glide module. The changes include fixing typos, renaming variables for consistency, and updating method names to follow a uniform naming convention.

Code Cleanup and Consistency Improvements:

  • Corrected a typo in the import statement and throughout the code by changing FtSeachOptions to FtSearchOptions in python/python/glide/__init__.py and python/python/glide/async_commands/server_modules/ft.py [1] [2] [3] [4].
  • Renamed variables for consistency, changing indexName to index_name in multiple functions in python/python/glide/async_commands/server_modules/ft.py [1] [2] [3] [4] [5] [6] [7] [8] [9] [10].
  • Updated method names from toArgs to to_args for consistency in python/python/glide/async_commands/server_modules/ft_options/ft_create_options.py [1] [2] [3] [4] [5] [6].
  • Corrected a typo in class name FtSeachKeywords to FtSearchKeywords in python/python/glide/async_commands/server_modules/ft_options/ft_constants.py.
  • Added a changelog entry for the Python code cleanup in CHANGELOG.md.

@prateek-kumar-improving
Copy link
Collaborator Author

prateek-kumar-improving commented Nov 4, 2024

Issue link

This Pull Request is linked to issue (URL): #2429

Checklist

Before submitting the PR make sure the following are checked:

* [x]  This Pull Request is related to one issue.

* [x]  Commit message has a detailed description of what changed and why.

* [x]  Tests are added or updated.

* [x]  CHANGELOG.md and documentation files are updated.

* [x]  Destination branch is correct - main or release

* [x]  Commits will be squashed upon merging.

Lazy blueprint for elaborating, you can edit with the real details:

This pull request focuses on code cleanup and consistency improvements in the Python codebase, specifically for the glide module. The changes include fixing typos, renaming variables for consistency, and updating method names to follow a uniform naming convention.

Code Cleanup and Consistency Improvements:

  • Corrected a typo in the import statement and throughout the code by changing FtSeachOptions to FtSearchOptions in python/python/glide/__init__.py and python/python/glide/async_commands/server_modules/ft.py [1] [2] [3] [4].
  • Renamed variables for consistency, changing indexName to index_name in multiple functions in python/python/glide/async_commands/server_modules/ft.py [1] [2] [3] [4] [5] [6] [7] [8] [9] [10].
  • Updated method names from toArgs to to_args for consistency in python/python/glide/async_commands/server_modules/ft_options/ft_create_options.py [1] [2] [3] [4] [5] [6].
  • Corrected a typo in class name FtSeachKeywords to FtSearchKeywords in python/python/glide/async_commands/server_modules/ft_options/ft_constants.py.
  • Added a changelog entry for the Python code cleanup in CHANGELOG.md.

I have updated the details in the PR description. I will follow this format of description for PRs created for any improvement PRs I create for other languages as well. Thanks.

Copy link
Collaborator

@avifenesh avifenesh left a comment

Choose a reason for hiding this comment

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

LGTM
We are freezing merges until CI is green again, then ill approve
Thanks!

@Yury-Fridlyand Yury-Fridlyand added the python Python wrapper label Nov 4, 2024
@acarbonetto acarbonetto merged commit 6e04584 into release-1.2 Nov 7, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Python wrapper
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants