Skip to content

MPT-17825: resolve WPS111 naming violations#135

Merged
d3rky merged 1 commit intomainfrom
codex/MPT-17825-adopt-wemake-rules-WPS111
Feb 18, 2026
Merged

MPT-17825: resolve WPS111 naming violations#135
d3rky merged 1 commit intomainfrom
codex/MPT-17825-adopt-wemake-rules-WPS111

Conversation

@svazquezco
Copy link
Contributor

@svazquezco svazquezco commented Feb 18, 2026

🤖 Codex-generated PR — Please review carefully.

Summary

  • remove WPS111 from flake8 per-file-ignores in pyproject.toml
  • rename short variables across source and tests to satisfy WPS111 (exceptions, iterators, lambdas, file handles)
  • keep behavior unchanged while aligning naming style with wemake

Validation

  • make check
  • make test

Closes MPT-17825

  • Remove WPS111 from flake8 per-file-ignores in pyproject.toml to adopt wemake naming rules.
  • Rename short/local variable names across source and tests to satisfy WPS111 while preserving behavior:
    • Exception variables: e → error
    • Iterators/loop vars: a → account, p → product_data, c → cell, r → record, i → index, etc.
    • Lambda parameters and comprehensions updated for clarity (e.g., a → account).
    • File handle variables: f → file_obj in JSON handlers and tests.
  • Narrow some except clauses to MPTAPIError where applicable; variable renames updated accordingly (behavior unchanged).
  • Tests updated and added:
    • Renamed test_update_item_error → test_update_item_api_list_error; added test_update_item_api_update_error.
    • Added tests for wrap_http_error covering no-response, structured field errors, and unstructured payloads.
  • Validation: make check and make test completed successfully.

@svazquezco svazquezco requested a review from a team as a code owner February 18, 2026 10:07
@svazquezco svazquezco force-pushed the codex/MPT-17825-adopt-wemake-rules-WPS111 branch from 48979e7 to f528d46 Compare February 18, 2026 13:34
@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

📝 Walkthrough

Walkthrough

Refactor-only changes renaming local variables for clarity (e.g., eerror, ffile_obj, short iterators → descriptive names) and tightening some except clauses to MPTAPIError. No public API signatures or control flow semantics were intentionally changed.

Changes

Cohort / File(s) Summary
Exception Variable Renames & narrowed excepts
cli/core/accounts/app.py, cli/core/errors.py, cli/core/price_lists/services/item_service.py, cli/core/price_lists/services/price_list_service.py, cli/core/products/services/product_service.py, cli/core/products/services/related_components_base_service.py, cli/plugins/audit_plugin/api.py
Replaced exception variable e with error in except blocks; several places now catch MPTAPIError explicitly instead of a generic Exception. Error message formatting updated to use error.
Iterator / Loop Variable Renames
cli/core/accounts/flows.py, cli/core/console.py, cli/core/file_discovery.py, cli/core/handlers/excel_file_handler.py, cli/core/mpt/flows.py
Renamed short loop/iterator variables to descriptive names (aaccount_item/account, pproduct_data/pattern, ccell, iindex). Logic and returns unchanged.
File Handle Variable Renames
cli/core/accounts/handlers/json_file_handler.py, tests/cli/core/accounts/handlers/test_json_file_handler.py, tests/cli/core/accounts/test_app.py, tests/cli/core/accounts/test_flows.py
Renamed with-open file handle ffile_obj in JSON read/write sites across code and tests. No behavioral change.
Tests: updates and additions
tests/cli/core/mpt/test_flows.py, tests/test_debug_logging.py, tests/cli/core/price_lists/services/test_item_service.py, tests/cli/core/test_errors.py, tests/...
Adjusted tests to match renames (exception context vars, iterator names). Added tests for wrap_http_error and a new failure case for item update API.
Lint config
pyproject.toml
Adjusted per-file-ignores list (removed specific WPS codes from ignores).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Jira Issue Key In Title ✅ Passed The PR title contains exactly one Jira issue key in the correct format (MPT-17825).
Test Coverage Required ✅ Passed PR modifies 14 code files and includes 7 test files with corresponding test coverage updates.
Single Commit Required ✅ Passed The PR contains exactly one commit (f2edab6 refactor: Resolve WPS111 naming violations), satisfying the single commit requirement with clean linear git history.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

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: 1

🧹 Nitpick comments (1)
cli/core/file_discovery.py (1)

26-26: Consider avoiding variable shadowing for clarity.

The lambda parameter file_path shadows the loop variable from line 17, which may reduce readability even though the loop has completed.

♻️ Alternative approaches to avoid shadowing

Option 1: Use a different parameter name

-    return list(filter(lambda file_path: file_path.endswith(".xlsx"), file_paths))
+    return list(filter(lambda path: path.endswith(".xlsx"), file_paths))

Option 2: Use a list comprehension (more Pythonic)

-    return list(filter(lambda file_path: file_path.endswith(".xlsx"), file_paths))
+    return [path for path in file_paths if path.endswith(".xlsx")]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/core/file_discovery.py` at line 26, The return statement in
file_discovery.py uses a lambda with parameter name file_path that shadows the
outer variable of the same name; to fix, avoid shadowing by either renaming the
lambda parameter (e.g., to p) or, preferably, replace the filter+lambda with a
list comprehension (e.g., [p for p in file_paths if p.endswith(".xlsx")]) inside
the same function to make intent clearer and improve readability.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cli/core/price_lists/services/price_list_service.py`:
- Around line 18-20: In the PriceListService.create method replace the broad
"except Exception as error" with "except MPTAPIError as error" so it matches
retrieve/retrieve_from_mpt/update; ensure MPTAPIError is imported where
PriceListService (or the create method) is defined, keep the existing
self._set_error(str(error)) and the ServiceResult(success=False,
errors=[str(error)], model=None, stats=self.stats) return unchanged.

---

Nitpick comments:
In `@cli/core/file_discovery.py`:
- Line 26: The return statement in file_discovery.py uses a lambda with
parameter name file_path that shadows the outer variable of the same name; to
fix, avoid shadowing by either renaming the lambda parameter (e.g., to p) or,
preferably, replace the filter+lambda with a list comprehension (e.g., [p for p
in file_paths if p.endswith(".xlsx")]) inside the same function to make intent
clearer and improve readability.

@svazquezco svazquezco force-pushed the codex/MPT-17825-adopt-wemake-rules-WPS111 branch from f528d46 to d61ba59 Compare February 18, 2026 13:58
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: 1

🧹 Nitpick comments (3)
cli/core/errors.py (2)

73-74: Consider adding exception chaining here as well.

Same as above - using raise ... from error preserves the exception chain for better debugging.

Suggested improvement
-            raise MPTAPIError(str(error), error.body)
+            raise MPTAPIError(str(error), error.body) from error
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/core/errors.py` around lines 73 - 74, The except block catching
APIException should preserve exception chaining; update the raise of MPTAPIError
in the except APIException as error handler to re-raise using exception chaining
(i.e., raise MPTAPIError(str(error), error.body) from error) so the original
APIException is preserved for debugging; locate the except APIException handler
and modify the raise to include "from error" referencing APIException and
MPTAPIError.

44-59: Variable renaming looks good. Consider adding exception chaining.

The rename from e to error and the inner loop variable change from error to error_details (to avoid shadowing) are correct.

The static analyzer suggests using raise ... from error to preserve the exception chain, which aids debugging by keeping the original traceback.

Suggested improvement
-            raise MPTAPIError(str(error), msg)
+            raise MPTAPIError(str(error), msg) from error
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/core/errors.py` around lines 44 - 59, Update the exception raise to
preserve the original traceback by using exception chaining: in the
RequestException handler where you currently call raise MPTAPIError(str(error),
msg), change it to raise MPTAPIError(str(error), msg) from error so the original
RequestException (error) is attached; this involves the try/except block
catching RequestException and the raise of MPTAPIError.
cli/core/products/services/product_service.py (1)

28-28: Narrow exception type from bare Exception to MPTAPIError for consistency.

Ruff flags these as BLE001: Do not catch blind exception: Exception. All three API methods called here—self.api.post(), self.api.exists(), and self.api.get()—are decorated with @wrap_http_error, which converts HTTP errors to MPTAPIError. The same file already uses MPTAPIError correctly on lines 35 and 134, so changing lines 28, 72, and 82 to catch MPTAPIError aligns with existing patterns and improves error clarity.

This appears to be pre-existing behavior not introduced by this PR, so it can be addressed separately if desired.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/core/products/services/product_service.py` at line 28, Change the three
broad except blocks that currently catch bare Exception around the API calls to
catch MPTAPIError instead: update the handlers that wrap calls to
self.api.post(), self.api.exists(), and self.api.get() so they except
MPTAPIError (the same error type already used elsewhere in ProductService) and
keep the existing error handling logic unchanged; this narrows the exception
type to the HTTP-wrapped error produced by the `@wrap_http_error` decorator and
aligns with existing usage of MPTAPIError in the class.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/cli/core/test_errors.py`:
- Line 1: Replace the direct use of unittest.mock.Mock with the pytest-mock
fixture: remove the "from unittest.mock import Mock" import and update the
affected test functions in tests/cli/core/test_errors.py (including the ones
around lines 26 and 38) to accept the pytest "mocker" fixture and use
mocker.Mock or mocker.patch in place of Mock; ensure any calls constructing
Mock() are replaced with mocker.Mock() and any patching uses mocker.patch so the
tests follow the pytest-mock guideline.

---

Duplicate comments:
In `@cli/core/price_lists/services/price_list_service.py`:
- Around line 18-20: Replace the broad except Exception in the method that
currently does "except Exception as error" with a specific "except MPTAPIError
as error" to match the other handlers (see retrieve, retrieve_from_mpt, update)
so you only catch the expected MPT API failures; keep the existing error
handling body (self._set_error(str(error)) and returning ServiceResult(...))
unchanged.

---

Nitpick comments:
In `@cli/core/errors.py`:
- Around line 73-74: The except block catching APIException should preserve
exception chaining; update the raise of MPTAPIError in the except APIException
as error handler to re-raise using exception chaining (i.e., raise
MPTAPIError(str(error), error.body) from error) so the original APIException is
preserved for debugging; locate the except APIException handler and modify the
raise to include "from error" referencing APIException and MPTAPIError.
- Around line 44-59: Update the exception raise to preserve the original
traceback by using exception chaining: in the RequestException handler where you
currently call raise MPTAPIError(str(error), msg), change it to raise
MPTAPIError(str(error), msg) from error so the original RequestException (error)
is attached; this involves the try/except block catching RequestException and
the raise of MPTAPIError.

In `@cli/core/products/services/product_service.py`:
- Line 28: Change the three broad except blocks that currently catch bare
Exception around the API calls to catch MPTAPIError instead: update the handlers
that wrap calls to self.api.post(), self.api.exists(), and self.api.get() so
they except MPTAPIError (the same error type already used elsewhere in
ProductService) and keep the existing error handling logic unchanged; this
narrows the exception type to the HTTP-wrapped error produced by the
`@wrap_http_error` decorator and aligns with existing usage of MPTAPIError in the
class.

@svazquezco svazquezco force-pushed the codex/MPT-17825-adopt-wemake-rules-WPS111 branch from d61ba59 to f2edab6 Compare February 18, 2026 14:09
@sonarqubecloud
Copy link

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.

🧹 Nitpick comments (2)
cli/plugins/audit_plugin/api.py (1)

14-14: Consider narrowing exception types (out of scope for this PR).

Ruff flags BLE001 on the blind except Exception clauses. This is a pre-existing pattern, not introduced by your changes. As a future improvement, consider catching more specific exceptions (e.g., requests.RequestException or the client's specific error type) to avoid masking unexpected errors.

Also applies to: 36-36

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/plugins/audit_plugin/api.py` at line 14, Replace the broad "except
Exception as error" handlers in the audit plugin API (the two occurrences of
"except Exception as error") with narrower exception types appropriate to the
operations being performed (e.g., requests.RequestException for HTTP calls, the
specific client's error class for client calls, or ValueError/IOError where
applicable), and add the necessary imports; if multiple error types must be
handled, use separate except blocks or a tuple of exception classes to avoid
masking unexpected exceptions while preserving existing error-logging behavior.
tests/cli/core/price_lists/services/test_item_service.py (1)

129-147: Assert the update call to lock the failure path.
Without asserting the update invocation, this test could pass even if the update path is skipped in future changes.

Proposed tweak
-    mocker.patch.object(
+    update_mock = mocker.patch.object(
         service_context.api,
         "update",
         side_effect=MPTAPIError("API Error", "Error updating item"),
     )
@@
-    file_handler_mock.assert_called()
+    update_mock.assert_called_once()
+    file_handler_mock.assert_called()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/cli/core/price_lists/services/test_item_service.py` around lines 129 -
147, The test test_update_item_api_update_error should explicitly assert that
the API update path was invoked; modify the test to assert that
service_context.api.update was called (e.g., using mocker to get the mock and
calling assert_called_once or assert_called_with) after calling
ItemService(service_context).update() so the failure path is locked in—reference
the mocked service_context.api.update and the ItemService.update invocation and
keep the existing assertions on result.success, result.errors, and
file_manager.write_error.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cli/plugins/audit_plugin/api.py`:
- Line 14: Replace the broad "except Exception as error" handlers in the audit
plugin API (the two occurrences of "except Exception as error") with narrower
exception types appropriate to the operations being performed (e.g.,
requests.RequestException for HTTP calls, the specific client's error class for
client calls, or ValueError/IOError where applicable), and add the necessary
imports; if multiple error types must be handled, use separate except blocks or
a tuple of exception classes to avoid masking unexpected exceptions while
preserving existing error-logging behavior.

In `@tests/cli/core/price_lists/services/test_item_service.py`:
- Around line 129-147: The test test_update_item_api_update_error should
explicitly assert that the API update path was invoked; modify the test to
assert that service_context.api.update was called (e.g., using mocker to get the
mock and calling assert_called_once or assert_called_with) after calling
ItemService(service_context).update() so the failure path is locked in—reference
the mocked service_context.api.update and the ItemService.update invocation and
keep the existing assertions on result.success, result.errors, and
file_manager.write_error.

@d3rky d3rky merged commit 4decf7d into main Feb 18, 2026
4 checks passed
@d3rky d3rky deleted the codex/MPT-17825-adopt-wemake-rules-WPS111 branch February 18, 2026 15:00
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.

2 participants