Skip to content

Commit e5b9b3a

Browse files
authored
MPT-17825: resolve WPS400 and WPS407 violations (#163)
🤖 **Codex-generated PR** — Please review carefully. ## Summary - remove obsolete ignores for WPS400, WPS402, WPS420, and WPS458 - resolve WPS400 in package re-exports by using explicit F401 ignores with absolute imports - resolve WPS407 by making shared constants read-only and replacing the mutable stats template with a factory ## Validation - make check - make check-all <!-- This is an auto-generated comment: release notes by coderabbit.ai --> Closes [MPT-17825](https://softwareone.atlassian.net/browse/MPT-17825) ## Changes - Converted relative imports to absolute imports in package `__init__.py` files (`accounts`, `price_lists`, `products`) and added explicit `__all__` declarations to define public APIs - Made module-level constants immutable by wrapping dictionaries with `MappingProxyType` in `accounts/constants.py`, `price_lists/constants.py`, and `products/constants.py` - Updated class attributes in `PriceListExcelFileManager` and `ProductExcelFileManager` to directly reference immutable constants instead of wrapping them again - Introduced `default_results()` factory function in `stats.py` to replace mutable `DEFAULT_RESULTS` and removed reliance on `deepcopy()` for stats initialization - Removed WPS458 from flake8 per-file-ignores in `pyproject.toml` <!-- end of auto-generated comment: release notes by coderabbit.ai --> [MPT-17825]: https://softwareone.atlassian.net/browse/MPT-17825?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2 parents 0220dad + f30eddf commit e5b9b3a

File tree

10 files changed

+47
-38
lines changed

10 files changed

+47
-38
lines changed

cli/core/accounts/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from .app import app # noqa
1+
from cli.core.accounts.app import app
2+
3+
__all__ = ["app"]

cli/core/accounts/constants.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
from types import MappingProxyType
2+
13
CREATING = "creating"
24
FETCHING = "fetching"
35
READING = "reading"
46
REMOVING = "removing"
57

6-
STATUS_MSG = {
8+
STATUS_MSG = MappingProxyType({
79
CREATING: "Making account",
810
FETCHING: "Fetching account information",
911
READING: "Reading accounts from the configuration file",
1012
REMOVING: "Removing account",
11-
}
13+
})

cli/core/price_lists/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from .app import app # noqa
1+
from cli.core.price_lists.app import app
2+
3+
__all__ = ["app"]

cli/core/price_lists/constants.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from collections.abc import Mapping
2+
from types import MappingProxyType
13
from typing import Any
24

35
ERROR_COLUMN_NAME = "Error"
@@ -8,7 +10,7 @@
810
TAB_PRICE_ITEMS,
911
)
1012

11-
REQUIRED_FIELDS_BY_TAB: dict[str, Any] = {}
13+
REQUIRED_FIELDS_BY_TAB: Mapping[str, Any] = MappingProxyType({})
1214

1315
GENERAL_PRICELIST_ID = "Pricelist ID"
1416
GENERAL_CURRENCY = "Currency"

cli/core/price_lists/handlers/price_list_excel_file_manager.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from types import MappingProxyType
2-
31
from cli.core.handlers.vertical_tab_file_manager import VerticalTabFileManager
42
from cli.core.price_lists.constants import (
53
GENERAL_FIELDS,
@@ -18,5 +16,5 @@ class PriceListExcelFileManager(VerticalTabFileManager):
1816
_fields = GENERAL_FIELDS
1917
_id_field = GENERAL_PRICELIST_ID
2018
_required_tabs = REQUIRED_TABS
21-
_required_fields_by_tab = MappingProxyType(REQUIRED_FIELDS_BY_TAB)
19+
_required_fields_by_tab = REQUIRED_FIELDS_BY_TAB
2220
_sheet_name = TAB_GENERAL

cli/core/products/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from .app import app # noqa
1+
from cli.core.products.app import app
2+
3+
__all__ = ["app"]

cli/core/products/constants.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from types import MappingProxyType
2+
13
ID_COLUMN_NAME = "ID"
24
ACTION_COLUMN_NAME = "Action"
35
CREATED_COLUMN_NAME = "Created"
@@ -271,7 +273,7 @@
271273
SETTINGS_SETTING,
272274
SETTINGS_VALUE,
273275
)
274-
SETTINGS_API_MAPPING = {
276+
SETTINGS_API_MAPPING = MappingProxyType({
275277
"Change order validation (draft)": "preValidation.changeOrderDraft",
276278
"Item selection validation": "itemSelection",
277279
"Order queue changes notification": "orderQueueChanges",
@@ -283,15 +285,15 @@
283285
"Purchase order validation (draft)": "preValidation.purchaseOrderDraft",
284286
"Purchase order validation (query)": "preValidation.purchaseOrderQuery",
285287
"Termination order validation (draft)": "preValidation.terminationOrder",
286-
}
288+
})
287289
SETTINGS_FIELDS = (
288290
SETTINGS_SETTING,
289291
SETTINGS_ACTION,
290292
SETTINGS_VALUE,
291293
)
292294

293295

294-
REQUIRED_FIELDS_BY_TAB = {
296+
REQUIRED_FIELDS_BY_TAB = MappingProxyType({
295297
TAB_GENERAL: GENERAL_REQUIRED_FIELDS,
296298
TAB_PARAMETERS_GROUPS: PARAMETERS_GROUPS_REQUIRED_FIELDS,
297299
TAB_ITEMS_GROUPS: ITEMS_GROUPS_REQUIRED_FIELDS,
@@ -302,8 +304,8 @@
302304
TAB_ITEMS: ITEMS_REQUIRED_FIELDS,
303305
TAB_TEMPLATES: TEMPLATES_REQUIRED_FIELDS,
304306
TAB_SETTINGS: SETTINGS_REQUIRED_FIELDS,
305-
}
307+
})
306308

307-
REQUIRED_FIELDS_WITH_VALUES_BY_TAB = {
309+
REQUIRED_FIELDS_WITH_VALUES_BY_TAB = MappingProxyType({
308310
TAB_GENERAL: GENERAL_REQUIRED_FIELDS_WITH_VALUES,
309-
}
311+
})

cli/core/products/handlers/product_excel_file_manager.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from types import MappingProxyType
2-
31
from cli.core.handlers.vertical_tab_file_manager import VerticalTabFileManager
42
from cli.core.products.constants import (
53
GENERAL_FIELDS,
@@ -18,5 +16,5 @@ class ProductExcelFileManager(VerticalTabFileManager):
1816
_fields = GENERAL_FIELDS
1917
_id_field = GENERAL_PRODUCT_ID
2018
_required_tabs = REQUIRED_TABS
21-
_required_fields_by_tab = MappingProxyType(REQUIRED_FIELDS_BY_TAB)
19+
_required_fields_by_tab = REQUIRED_FIELDS_BY_TAB
2220
_sheet_name = TAB_GENERAL

cli/core/stats.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import copy
21
from abc import ABC, abstractmethod
32
from typing import TypedDict
43

@@ -23,12 +22,14 @@ class TabResults(TypedDict):
2322
skipped: int
2423

2524

26-
DEFAULT_RESULTS: TabResults = {
27-
"synced": 0,
28-
"error": 0,
29-
"total": 0,
30-
"skipped": 0,
31-
}
25+
def default_results() -> TabResults:
26+
"""Create a fresh statistics container."""
27+
return {
28+
"synced": 0,
29+
"error": 0,
30+
"total": 0,
31+
"skipped": 0,
32+
}
3233

3334

3435
class ErrorMessagesCollector:
@@ -186,16 +187,16 @@ class ProductStatsCollector(StatsCollector):
186187
"""Statistics collector specifically for product synchronization operations."""
187188

188189
def __init__(self) -> None:
189-
general: TabResults = copy.deepcopy(DEFAULT_RESULTS)
190-
parameters_groups: TabResults = copy.deepcopy(DEFAULT_RESULTS)
191-
items_groups: TabResults = copy.deepcopy(DEFAULT_RESULTS)
192-
agreements_parameters: TabResults = copy.deepcopy(DEFAULT_RESULTS)
193-
asset_parameters: TabResults = copy.deepcopy(DEFAULT_RESULTS)
194-
item_parameters: TabResults = copy.deepcopy(DEFAULT_RESULTS)
195-
request_parameters: TabResults = copy.deepcopy(DEFAULT_RESULTS)
196-
subscription_parameters: TabResults = copy.deepcopy(DEFAULT_RESULTS)
197-
item_rows: TabResults = copy.deepcopy(DEFAULT_RESULTS)
198-
templates: TabResults = copy.deepcopy(DEFAULT_RESULTS)
190+
general: TabResults = default_results()
191+
parameters_groups: TabResults = default_results()
192+
items_groups: TabResults = default_results()
193+
agreements_parameters: TabResults = default_results()
194+
asset_parameters: TabResults = default_results()
195+
item_parameters: TabResults = default_results()
196+
request_parameters: TabResults = default_results()
197+
subscription_parameters: TabResults = default_results()
198+
item_rows: TabResults = default_results()
199+
templates: TabResults = default_results()
199200

200201
tabs = {
201202
"General": general,
@@ -225,8 +226,8 @@ class PriceListStatsCollector(StatsCollector):
225226
"""
226227

227228
def __init__(self) -> None:
228-
general: TabResults = copy.deepcopy(DEFAULT_RESULTS)
229-
price_items: TabResults = copy.deepcopy(DEFAULT_RESULTS)
229+
general: TabResults = default_results()
230+
price_items: TabResults = default_results()
230231

231232
tabs = {
232233
"General": general,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ select = ["AAA", "E999", "WPS"]
121121
show-source = true
122122
statistics = false
123123
per-file-ignores = [
124-
"*.py:WPS204,WPS210,WPS211,WPS213,WPS214,WPS218,WPS221,WPS229,WPS231,WPS232,WPS234,WPS235,WPS237,WPS322,WPS327,WPS332,WPS335,WPS336,WPS338,WPS339,WPS342,WPS347,WPS349,WPS400,WPS407,WPS410,WPS412,WPS420,WPS432,WPS458",
124+
"*.py:WPS204,WPS210,WPS211,WPS213,WPS214,WPS218,WPS221,WPS229,WPS231,WPS232,WPS234,WPS235,WPS237,WPS322,WPS327,WPS332,WPS335,WPS336,WPS338,WPS339,WPS342,WPS347,WPS349,WPS410,WPS412,WPS432",
125125
"tests/**:WPS202,WPS203,WPS204,WPS210,WPS211,WPS213,WPS218,WPS221,WPS235,WPS322,WPS335,WPS339,WPS342,WPS432"
126126
]
127127

0 commit comments

Comments
 (0)