PTHMINT-45 Fix ruff error code ANN201#16
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances type safety and code readability by adding explicit return type annotations to methods and validators, and updates configuration to enforce stricter type annotation rules. Key changes include:
- Adding return type annotations to various validators and model methods.
- Updating type annotations for checkout and cart-related methods.
- Removing the "ANN201" rule from the pyproject.toml ignore list.
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/multisafepay/value_object/ip_address.py | Added explicit return type to IP address validator. |
| src/multisafepay/value_object/iban_number.py | Added explicit return type to IBAN number validator. |
| src/multisafepay/value_object/gender.py | Added return type to validator; note possible naming inconsistency. |
| src/multisafepay/value_object/email_address.py | Added explicit return type to email address validator. |
| src/multisafepay/value_object/currency.py | Added explicit return type to currency validator. |
| src/multisafepay/value_object/country.py | Added explicit return type to country validator. |
| src/multisafepay/util/version.py | Added return type to set_plugin_version method. |
| src/multisafepay/util/dict_utils.py | Added return type annotation to merge_recursive. |
| src/multisafepay/exception/api.py | Added explicit return type to get_context_value. |
| src/multisafepay/client/api_key.py | Added explicit return type to API key validator. |
| src/multisafepay/api/shared/cart/shopping_cart.py | Added return type annotations to add_items and add_item methods. |
| src/multisafepay/api/paths/orders/order_id/refund/request/components/checkout_data.py | Added return type annotations to checkout data methods (add_items, add_item, get_items, etc.). |
| src/multisafepay/api/paths/capture/request/capture_request.py | Added return types to add_status and add_reason methods. |
| src/multisafepay/api/base/response/custom_api_response.py | Added explicit return type to get_data method. |
| src/multisafepay/api/base/listings/listing.py | Added explicit return type annotation to the append method. |
| pyproject.toml | Removed the "ANN201" rule from the ignore list to enforce stricter type annotations. |
Comments suppressed due to low confidence (2)
src/multisafepay/value_object/gender.py:29
- [nitpick] The function name 'validate_ip_address' is misleading in the context of validating a gender value. Consider renaming it to 'validate_gender' for clarity.
def validate_ip_address(cls: "Gender", value: str) -> str:
src/multisafepay/api/paths/orders/order_id/refund/request/components/checkout_data.py:29
- The default parameter value for 'items' is an empty tuple, which conflicts with the expected List[CartItem] type. Consider using an empty list ([]) instead.
def add_items(self: "CheckoutData", items: List[CartItem] = (),
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #16 +/- ##
=======================================
Coverage 90.76% 90.76%
=======================================
Files 106 106
Lines 2306 2307 +1
=======================================
+ Hits 2093 2094 +1
Misses 213 213 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces type annotations to several methods across the codebase, enhancing type safety and improving code readability. It also includes minor adjustments to imports and configuration files. Below is a categorized summary of the most important changes:
Type Annotations for Methods
Added return type annotations to various methods, such as
appendinlisting.py,get_dataincustom_api_response.py, andadd_statusincapture_request.py. These changes ensure that method return types are explicit and consistent. [1] [2] [3]Updated methods in
checkout_data.pyto include return type annotations, such asadd_items,get_items, andget_item_by_merchant_item_id, improving clarity in the refund request components. [1] [2] [3]Added type annotations to validators in value object models like
ApiKey,Country, andCurrency, ensuring that validation methods explicitly returnstr. [1] [2] [3]Configuration and Import Adjustments
Removed the
ANN201rule from theignorelist inpyproject.toml, likely indicating stricter adherence to type annotation rules.Added the
Anytype to imports inapi.pyto support new type annotations.These changes collectively improve the maintainability and robustness of the codebase by making type expectations explicit.