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

⚡ decode returns dict[str, Any] instead of dict #4

Merged
merged 3 commits into from
May 18, 2024

Conversation

techouse
Copy link
Owner

@techouse techouse commented May 18, 2024

Description

decode now returns dict[str, Any] instead of dict.

NOTE: This means that all decoded dict keys will now be strings.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

The tests have been updated to reflect the change.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • Documentation

    • Updated type annotations in documentation for better clarity and accuracy.
  • Bug Fixes

    • Ensured dictionary keys are correctly handled as strings in decoding operations.
  • Tests

    • Modified test cases to reflect changes from integer keys to string keys in dictionaries.
  • Refactor

    • Improved type hints for better code readability and maintainability.

@techouse techouse added the enhancement New feature or request label May 18, 2024
@techouse techouse self-assigned this May 18, 2024
Copy link

coderabbitai bot commented May 18, 2024

Walkthrough

The updates focus on refining type annotations and ensuring dictionary keys are treated as strings in the qs_codec module. This involves changes to the decode function, various utility methods, and related test cases. The modifications enhance type safety and consistency across the codebase.

Changes

File(s) Change Summary
README.rst, docs/README.rst Updated type annotations and dictionary key types in code snippets and function signatures.
src/qs_codec/decode.py Enhanced decode function with more specific type hints and initialization of an empty dictionary.
src/qs_codec/utils/utils.py Updated type hints in merge and compact methods to ensure dictionary keys are strings.
tests/unit/decode_test.py, example_test.py Modified test cases to use string keys in dictionaries for decoding operations.
tests/unit/utils_test.py Adjusted test cases to reflect the use of string keys in dictionaries for utility methods.

In fields of code where logic blooms,
The keys now sing in stringy tunes.
Decoding paths with clearer sight,
Type hints guide us through the night.
With tests aligned and errors few,
Our codebase shines in structure new.
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.00% (target: -1.00%) 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (060e82b) 709 686 96.76%
Head commit (75571e4) 709 (+0) 686 (+0) 96.76% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#4) 12 12 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy will stop sending the deprecated coverage status from June 5th, 2024. Learn more

Copy link

codecov bot commented May 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.75%. Comparing base (060e82b) to head (75571e4).

Additional details and impacted files
@@           Coverage Diff           @@
##             main       #4   +/-   ##
=======================================
  Coverage   96.75%   96.75%           
=======================================
  Files          16       16           
  Lines         709      709           
=======================================
  Hits          686      686           
  Misses         23       23           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 060e82b and 75571e4.
Files selected for processing (7)
  • README.rst (4 hunks)
  • docs/README.rst (4 hunks)
  • src/qs_codec/decode.py (5 hunks)
  • src/qs_codec/utils/utils.py (4 hunks)
  • tests/unit/decode_test.py (8 hunks)
  • tests/unit/example_test.py (1 hunks)
  • tests/unit/utils_test.py (3 hunks)
Files skipped from review due to trivial changes (1)
  • tests/unit/example_test.py
Additional comments not posted (19)
src/qs_codec/decode.py (5)

17-19: Updated function signature to t.Dict[str, t.Any] aligns with the PR's objective to ensure all dictionary keys are strings.


25-25: Initialization of obj with type t.Dict[str, t.Any] is consistent with the new function signature.


28-28: Proper handling of empty input values by returning an empty dictionary.


57-57: Parsing logic in _parse_query_string_values appears robust and handles various encoding scenarios.


Line range hint 127-161: Complex parsing logic in _parse_object handles nested structures and list indexing correctly.

src/qs_codec/utils/utils.py (3)

18-21: Updated type hints in merge method to ensure dictionary keys are treated as strings, aligning with PR objectives.


63-63: Handling of list and tuple sources in merge method ensures that indices are treated as string keys, which is crucial for consistency.

Also applies to: 75-75


104-104: Implementation of compact method effectively removes Undefined values from dictionaries, maintaining data integrity.

tests/unit/utils_test.py (3)

424-424: Updated test case correctly reflects the change in handling dictionary keys as strings.


453-453: Test case update correctly reflects the handling of dictionary keys as strings in complex structures.


465-471: Test case update ensures that dictionary keys are treated as strings, aligning with the changes made in the utility functions.

docs/README.rst (5)

14-14: Updated function signature in documentation aligns with the new return type.


306-306: Example correctly demonstrates handling of list indices beyond the specified limit.


318-318: Example correctly demonstrates the effect of setting the list limit to 0.


330-330: Example correctly demonstrates the effect of disabling list parsing.


338-338: Example correctly demonstrates the merging behavior when mixing list and dictionary notations.

tests/unit/decode_test.py (2)

21-21: Ensure the test cases reflect the updated type annotations in the decode function.

Verification successful

The search did not return any occurrences of the old type annotations in decode_test.py. This suggests that the test cases have been updated to reflect the new type annotations.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the test cases in `decode_test.py` are updated to reflect the new type annotations.

# Test: Search for the function usage with old type annotations. Expect: No occurrences of the old type.
rg --type python $'decode(encoded: str, options: DecodeOptions = None) -> t.Mapping' tests/unit/decode_test.py

Length of output: 142



Script:

#!/bin/bash
# Description: Verify that the test cases in `decode_test.py` are updated to reflect the new type annotations.

# Test: Search for the function usage with old type annotations. Expect: No occurrences of the old type.
rg 'decode(encoded: str, options: DecodeOptions = None) -> t.Mapping' tests/unit/decode_test.py

Length of output: 97


192-192: The changes in these lines are consistent with the PR's objective to handle dictionary keys as strings and improve the handling of list indices and dictionary transformations.

Also applies to: 197-197, 199-199, 220-224, 248-252, 259-259, 310-311, 336-341, 344-345, 489-489, 536-537, 539-539

README.rst (1)

40-40: The update in the function signature correctly reflects the new return type as t.Dict[str, t.Any], aligning with the PR's objectives.

@techouse techouse merged commit f8a6172 into main May 18, 2024
16 checks passed
@techouse techouse deleted the chore/decode-dict-str-any branch May 18, 2024 22:25
techouse added a commit that referenced this pull request May 18, 2024
## 0.2.2

- #4
- fix decoding encoded square brackets in key names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant