Skip to content

Commit

Permalink
馃Ч Switch to mypy --strict (#308)
Browse files Browse the repository at this point in the history
* 馃Ч Switch to `mypy --strict`

* aaaalter

* dann halt nicht

* blub

* sfsdfd

* aha!
  • Loading branch information
hf-kklein committed May 17, 2024
1 parent 9f380dd commit 3dbc4e7
Show file tree
Hide file tree
Showing 37 changed files with 101 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/kohlrahbi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@click.group()
@click.version_option(version=version)
def cli():
def cli() -> None:
"""Kohlrahbi CLI tool"""


Expand Down
6 changes: 3 additions & 3 deletions src/kohlrahbi/ahb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def process_ahb_table(
pruefi: str,
output_path: Path,
file_type: str,
):
) -> None:
"""
Process the ahb table.
"""
Expand Down Expand Up @@ -98,7 +98,7 @@ def process_pruefi(
path_to_ahb_docx_file: Path,
output_path: Path,
file_type: str,
):
) -> None:
"""
Process one pruefi.
If the input path ends with .docx, we assume that the file containing the pruefi is given.
Expand Down Expand Up @@ -183,7 +183,7 @@ def extract_pruefis_from_table(table: Table) -> list[str]:

def table_header_contains_text_pruefidentifikator(table: Table) -> bool:
"""Checks if the table header contains the text 'Pr眉fidentifikator'."""
return table.row_cells(0)[-1].paragraphs[-1].text.startswith("Pr眉fidentifikator")
return table.row_cells(0)[-1].paragraphs[-1].text.startswith("Pr眉fidentifikator") # type:ignore[no-any-return]


def get_pruefi_to_file_mapping(basic_input_path: Path, format_version: EdifactFormatVersion) -> dict[str, str]:
Expand Down
6 changes: 3 additions & 3 deletions src/kohlrahbi/ahb/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from kohlrahbi.enums.ahbexportfileformat import AhbExportFileFormat


def check_python_version():
def check_python_version() -> None:
"""
Check if the Python interpreter is greater or equal to 3.11
"""
Expand All @@ -24,7 +24,7 @@ def check_python_version():


# pylint: disable=unused-argument
def validate_path(ctx, param, value):
def validate_path(ctx, param, value) -> Path: # type:ignore[no-untyped-def]
"""
Ensure the path exists or offer to create it.
"""
Expand Down Expand Up @@ -97,7 +97,7 @@ def ahb(
format_version: EdifactFormatVersion | str,
assume_yes: bool, # pylint: disable=unused-argument
# it is used by the callback function of the output-path
):
) -> None:
"""
Scrape AHB documents for pruefidentifikatoren.
This is a command line interface for the pruefis module.
Expand Down
3 changes: 2 additions & 1 deletion src/kohlrahbi/ahbtable/ahbcondtions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ def collect_conditions(
logger.info("The package conditions for %s were collected.", edifact_format)
return conditions_dict

def include_condition_dict(self, to_add=dict[EdifactFormat, dict[str, str]] | None) -> None:
def include_condition_dict(self, to_add: dict[EdifactFormat, dict[str, str]] | None) -> None:
""" " Include a dict of conditions to the conditions_dict"""
if to_add is None:
logger.info("Conditions dict to be added is empty.")
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:
Expand Down
5 changes: 3 additions & 2 deletions src/kohlrahbi/ahbtable/ahbpackagetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def provide_conditions(self, edifact_format: EdifactFormat) -> dict[EdifactForma
logger.info("The package conditions for %s were collected.", edifact_format)
return conditions_dict

def provide_packages(self, edifact_format: EdifactFormat):
def provide_packages(self, edifact_format: EdifactFormat) -> None:
"""collect conditions from package table and store them in conditions dict."""
package_dict: dict[EdifactFormat, dict[str, str]] = {edifact_format: {}}

Expand Down Expand Up @@ -80,10 +80,11 @@ def provide_packages(self, edifact_format: EdifactFormat):
logger.info("Packages for %s were collected.", edifact_format)
self.package_dict = package_dict

def include_package_dict(self, to_add=dict[EdifactFormat, dict[str, str]] | None) -> None:
def include_package_dict(self, to_add: dict[EdifactFormat, dict[str, str]] | None) -> None:
"""Include a dict of conditions to the conditions_dict"""
if to_add is None:
logger.info("Packages dict to be added is empty.")
return
for edifact_format, edi_cond_dict in to_add.items():
for package_key, package_conditions in edi_cond_dict.items():
if edifact_format in self.package_dict:
Expand Down
7 changes: 4 additions & 3 deletions src/kohlrahbi/ahbtable/ahbsubtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

import pandas as pd
from docx.table import Table as DocxTable
from docx.table import _Cell
from docx.table import _Cell, _Row
from pydantic import BaseModel, ConfigDict

from kohlrahbi.ahbtable.ahbtablerow import AhbTableRow
from kohlrahbi.row_type_checker import RowType, get_row_type
from kohlrahbi.enums import RowType
from kohlrahbi.row_type_checker import get_row_type
from kohlrahbi.seed import Seed


Expand Down Expand Up @@ -122,7 +123,7 @@ def from_headless_table(cls, tmd: Seed, docx_table: DocxTable) -> "AhbSubTable":
return cls(table_meta_data=tmd, table=ahb_table_dataframe)

@staticmethod
def iter_visible_cells(row) -> Generator[_Cell, None, None]:
def iter_visible_cells(row: _Row) -> Generator[_Cell, None, None]:
"""
This function makes sure that you will iterate over the cells you see in the word document.
For more information go to https://github.com/python-openxml/python-docx/issues/970#issuecomment-877386927
Expand Down
2 changes: 1 addition & 1 deletion src/kohlrahbi/ahbtable/ahbtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def append_ahb_sub_table(self, ahb_sub_table: AhbSubTable) -> None:
self.table = pd.concat([self.table, ahb_sub_table.table], ignore_index=True)

@staticmethod
def line_contains_only_segment_gruppe(raw_line: pd.Series) -> bool:
def line_contains_only_segment_gruppe(raw_line: pd.Series) -> bool: # type:ignore[type-arg]
"""
Returns true if the given raw line only contains some meaningful data in the "Segment Gruppe" key
"""
Expand Down
6 changes: 4 additions & 2 deletions src/kohlrahbi/ahbtable/ahbtablerow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pydantic import BaseModel, ConfigDict

from kohlrahbi.docxtablecells import BedingungCell, BodyCell, EdifactStrukturCell
from kohlrahbi.row_type_checker import RowType
from kohlrahbi.enums import RowType
from kohlrahbi.seed import Seed


Expand Down Expand Up @@ -46,7 +46,9 @@ def parse(
dtype="str",
)
# pylint: disable=unsubscriptable-object, no-member
empty_row: pd.Series[str] = pd.Series(len(ahb_row_dataframe.columns) * [""], index=self.seed.column_headers)
empty_row: pd.Series = pd.Series( # type:ignore[type-arg]
len(ahb_row_dataframe.columns) * [""], index=self.seed.column_headers
)

ahb_row_dataframe = pd.concat([ahb_row_dataframe, empty_row.to_frame().T], ignore_index=True)

Expand Down
2 changes: 1 addition & 1 deletion src/kohlrahbi/changehistory/changehistorytable.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def is_empty(val: str) -> bool:
return pd.isna(val) or val == ""

# Define a function to check if a value is considered empty for our case
def is_the_first_column_empty(row: pd.Series) -> bool:
def is_the_first_column_empty(row: pd.Series) -> bool: # type:ignore[type-arg]
"""
Checks if the first column of the given row is empty.
This is our indicator if the current row is a continuation of the upper row.
Expand Down
2 changes: 1 addition & 1 deletion src/kohlrahbi/changehistory/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def changehistory(
format_version: EdifactFormatVersion | str,
assume_yes: bool, # pylint: disable=unused-argument
# it is used by the callback function of the output-path
):
) -> None:
"""
Scrape change histories from the input path and save them to the output path.
Expand Down
1 change: 0 additions & 1 deletion src/kohlrahbi/conditions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def scrape_conditions(
for edifact_format, files in all_format_files.items():
for file in files:
# pylint: disable=too-many-function-args
# type: ignore[call-arg, arg-type]
path: Path = basic_input_path / path_to_file / Path(file)
doc = docx.Document(str(path.absolute()))
logger.info("Start scraping conditions for %s in %s", edifact_format, file)
Expand Down
6 changes: 3 additions & 3 deletions src/kohlrahbi/conditions/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from kohlrahbi.conditions import scrape_conditions


def check_python_version():
def check_python_version() -> None:
"""
Check if the Python interpreter is greater or equal to 3.11
"""
Expand All @@ -40,7 +40,7 @@ def check_python_version():


# pylint: disable=unused-argument
def validate_path(ctx, param, value):
def validate_path(ctx, param, value) -> Path: # type:ignore[no-untyped-def]
"""
Ensure the path exists or offer to create it.
"""
Expand Down Expand Up @@ -91,7 +91,7 @@ def validate_path(ctx, param, value):
)
def conditions(
edi_energy_mirror_path: Path, output_path: Path, format_version: EdifactFormatVersion | str, assume_yes: bool
):
) -> None:
"""
Scrape AHB documents for conditions.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/kohlrahbi/docxfilefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def filter_docx_files_for_edifact_format(self, edifact_format: EdifactFormat) ->

self.paths_to_docx_files = [path for path in self.paths_to_docx_files if str(edifact_format) in path.name]

def remove_temporary_files(self):
def remove_temporary_files(self) -> None:
"""
This method removes all temporary files from paths_to_docx_files.
Temporary files lead to the exception `BadZipFile: File is not a zip file`.
Expand Down
2 changes: 2 additions & 0 deletions src/kohlrahbi/docxtablecells/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
from .bedinungscell import BedingungCell
from .bodycell import BodyCell
from .edifactstrukturcell import EdifactStrukturCell

__all__ = ["BedingungCell", "BodyCell", "EdifactStrukturCell"]
5 changes: 3 additions & 2 deletions src/kohlrahbi/docxtablecells/bodycell.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pandas as pd
from docx.table import _Cell
from docx.text.paragraph import Paragraph
from maus.reader.flat_ahb_reader import FlatAhbCsvReader
from pydantic import BaseModel, ConfigDict

Expand Down Expand Up @@ -103,9 +104,9 @@ def parse(self, ahb_row_dataframe: pd.DataFrame) -> pd.DataFrame:

return ahb_row_dataframe

def has_paragraph_tabstops(self, paragraph) -> bool:
def has_paragraph_tabstops(self, paragraph: Paragraph) -> bool:
"""
Checks if the given paragraph contains tabstops
"""
tab_stops = list(paragraph.paragraph_format.tab_stops)
return len(tab_stops) > 0
return any(tab_stops)
2 changes: 2 additions & 0 deletions src/kohlrahbi/enums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

from .row_type import RowType
from .row_type_color import RowTypeColor

__all__ = ["RowType", "RowTypeColor"]
Loading

0 comments on commit 3dbc4e7

Please sign in to comment.