diff --git a/src/kohlrahbi/ahb/__init__.py b/src/kohlrahbi/ahb/__init__.py index 69f50afb..5a4c6609 100644 --- a/src/kohlrahbi/ahb/__init__.py +++ b/src/kohlrahbi/ahb/__init__.py @@ -153,6 +153,7 @@ def extract_pruefis_from_docx(docx_path: Path) -> Dict[str, str]: and table_header_starts_with_text_edifact_struktur(item) and table_header_contains_text_pruefidentifikator(item) ): + # pylint:disable=not-an-iterable pruefis.update({pruefi: docx_path.name for pruefi in extract_pruefis_from_table(item)}) return pruefis diff --git a/src/kohlrahbi/ahbtable/ahbcondtions.py b/src/kohlrahbi/ahbtable/ahbcondtions.py index f2296e72..7dfb828e 100644 --- a/src/kohlrahbi/ahbtable/ahbcondtions.py +++ b/src/kohlrahbi/ahbtable/ahbcondtions.py @@ -6,7 +6,7 @@ from docx.table import Table as DocxTable from maus.edifact import EdifactFormat -from pydantic import BaseModel, ConfigDict +from pydantic import BaseModel, ConfigDict, Field from kohlrahbi.logger import logger @@ -16,7 +16,7 @@ class AhbConditions(BaseModel): Class which contains a dict of conditions for each edifact format """ - conditions_dict: dict[EdifactFormat, dict[str, str]] = {} + conditions_dict: dict[EdifactFormat, dict[str, str]] = Field(default_factory=dict) model_config = ConfigDict(arbitrary_types_allowed=True) @@ -60,15 +60,19 @@ def include_condition_dict(self, to_add: dict[EdifactFormat, dict[str, str]] | N return for edifact_format, edi_cond_dict in to_add.items(): for condition_key, condition_text in edi_cond_dict.items(): - if edifact_format in self.conditions_dict: + if edifact_format in self.conditions_dict: # pylint:disable=unsupported-membership-test if ( + # pylint:disable=unsubscriptable-object condition_key in self.conditions_dict[edifact_format] and len(condition_text) > len(self.conditions_dict[edifact_format][condition_key]) + # pylint:disable=unsubscriptable-object or condition_key not in self.conditions_dict[edifact_format] ): self.conditions_dict[edifact_format][condition_key] = condition_text else: - self.conditions_dict[edifact_format] = {condition_key: condition_text} + self.conditions_dict[edifact_format] = { # pylint:disable=unsupported-assignment-operation + condition_key: condition_text + } logger.info("Conditions were updated.") @@ -78,6 +82,7 @@ def dump_as_json(self, output_directory_path: Path) -> None: The file will be stored in the directory: 'output_directory_path//conditions.json' """ + # pylint:disable=no-member for edifact_format, format_cond_dict in self.conditions_dict.items(): condition_json_output_directory_path = output_directory_path / str(edifact_format) condition_json_output_directory_path.mkdir(parents=True, exist_ok=True) diff --git a/src/kohlrahbi/ahbtable/ahbpackagetable.py b/src/kohlrahbi/ahbtable/ahbpackagetable.py index 22601bc1..2a2d284e 100644 --- a/src/kohlrahbi/ahbtable/ahbpackagetable.py +++ b/src/kohlrahbi/ahbtable/ahbpackagetable.py @@ -9,7 +9,7 @@ class which contains AHB package condition table import pandas as pd from docx.table import Table as DocxTable from maus.edifact import EdifactFormat -from pydantic import BaseModel, ConfigDict +from pydantic import BaseModel, ConfigDict, Field from kohlrahbi.ahbtable.ahbcondtions import parse_conditions_from_string from kohlrahbi.logger import logger @@ -23,7 +23,7 @@ class AhbPackageTable(BaseModel): """ table: pd.DataFrame = pd.DataFrame() - package_dict: dict[EdifactFormat, dict[str, str]] = {} + package_dict: dict[EdifactFormat, dict[str, str]] = Field(default_factory=dict) model_config = ConfigDict(arbitrary_types_allowed=True) @classmethod diff --git a/src/kohlrahbi/ahbtable/ahbtable.py b/src/kohlrahbi/ahbtable/ahbtable.py index 52cbb524..b83fe48d 100644 --- a/src/kohlrahbi/ahbtable/ahbtable.py +++ b/src/kohlrahbi/ahbtable/ahbtable.py @@ -8,7 +8,7 @@ import pandas as pd from maus.edifact import get_format_of_pruefidentifikator from more_itertools import peekable -from pydantic import BaseModel, ConfigDict +from pydantic import BaseModel, ConfigDict, Field from kohlrahbi.ahbtable.ahbsubtable import AhbSubTable from kohlrahbi.logger import logger @@ -32,7 +32,7 @@ class AhbTable(BaseModel): """ table: pd.DataFrame - metadata: list[PruefiMetaData] = [] + metadata: list[PruefiMetaData] = Field(default_factory=list) model_config = ConfigDict(arbitrary_types_allowed=True) diff --git a/src/kohlrahbi/read_functions.py b/src/kohlrahbi/read_functions.py index 419155f2..ed7fae1e 100644 --- a/src/kohlrahbi/read_functions.py +++ b/src/kohlrahbi/read_functions.py @@ -174,7 +174,7 @@ def process_table( """Processes tables to find and build the AHB table.""" if is_item_table_with_pruefidentifikatoren(item): seed = Seed.from_table(docx_table=item) - + # pylint:disable=unsupported-membership-test if pruefi in seed.pruefidentifikatoren and not searched_pruefi_is_found: log_found_pruefi(pruefi) ahb_sub_table = AhbSubTable.from_table_with_header(docx_table=item) diff --git a/src/kohlrahbi/seed.py b/src/kohlrahbi/seed.py index b051bc2b..faa89ebc 100644 --- a/src/kohlrahbi/seed.py +++ b/src/kohlrahbi/seed.py @@ -3,7 +3,7 @@ """ from docx.table import Table -from pydantic import BaseModel +from pydantic import BaseModel, Field from kohlrahbi.enums import RowType from kohlrahbi.table_header import PruefiMetaData, TableHeader, get_tabstop_positions @@ -15,13 +15,13 @@ class Seed(BaseModel): helper class to store all values to extract the AHB and the final AHB as dataframe """ - pruefidentifikatoren: list[str] = [] - column_headers: list[str] = [] + pruefidentifikatoren: list[str] = Field(default_factory=list) + column_headers: list[str] = Field(default_factory=list) edifact_struktur_left_indent_position: int = 0 middle_cell_left_indent_position: int = 0 - tabstop_positions: list[int] = [] - last_two_row_types: list[RowType] = [] - metadata: list[PruefiMetaData] = [] + tabstop_positions: list[int] = Field(default_factory=list) + last_two_row_types: list[RowType] = Field(default_factory=list) + metadata: list[PruefiMetaData] = Field(default_factory=list) # why this classmethod? # to decouple the data structure of Elixir from the input data diff --git a/src/kohlrahbi/table_header.py b/src/kohlrahbi/table_header.py index 892a7cf4..f0c71b8d 100644 --- a/src/kohlrahbi/table_header.py +++ b/src/kohlrahbi/table_header.py @@ -8,7 +8,7 @@ from docx.table import _Cell from docx.text.paragraph import Paragraph from more_itertools import first, last -from pydantic import BaseModel +from pydantic import BaseModel, Field class HeaderSection(StrEnum): @@ -93,7 +93,7 @@ class TableHeader(BaseModel): It contains the information about the Prüfidentifikatoren. """ - pruefi_meta_data: List[PruefiMetaData] = [] + pruefi_meta_data: List[PruefiMetaData] = Field(default_factory=list) @classmethod def from_header_cell(cls, row_cell: _Cell) -> "TableHeader": @@ -188,4 +188,5 @@ def get_pruefidentifikatoren(self) -> List[str]: The order of the Prüfidentifikatoren is the same as in the docx table headers. So there should be no duplicates. """ + # pylint:disable=not-an-iterable return [pruefi.pruefidentifikator for pruefi in self.pruefi_meta_data]