From 43f38694ba39c37e93d85957e988600297e9514b Mon Sep 17 00:00:00 2001 From: Philip Date: Tue, 8 Nov 2022 11:05:54 -0500 Subject: [PATCH 1/4] updated pre-commit with mypy --- .pre-commit-config.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 75ad87bf..759b27cf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -57,5 +57,10 @@ repos: args: [--prose-wrap=always, --print-width=88] exclude: ^.github/ISSUE_TEMPLATE/bug_report.md$ + - repo: https://github.com/pre-commit/mirrors-mypy + rev: "v0.982" + hooks: + - id: mypy + ci: autoupdate_schedule: quarterly From 49c8f0c78a7ea7fc89432dec60f1c3ebff7d463a Mon Sep 17 00:00:00 2001 From: Philip Date: Thu, 10 Nov 2022 21:03:05 -0500 Subject: [PATCH 2/4] Update .pre-commit-config.yaml added "pretty" and "show-error-codes" arguments and excluded "tests" Co-authored-by: Hugo van Kemenade --- .pre-commit-config.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 759b27cf..0c31aaff 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -61,6 +61,8 @@ repos: rev: "v0.982" hooks: - id: mypy + args: [--pretty, --show-error-codes] + exclude: ^tests/ ci: autoupdate_schedule: quarterly From db72297ffc9eab02cc7dff1ceccd9a0edaa24f49 Mon Sep 17 00:00:00 2001 From: Philip Date: Fri, 11 Nov 2022 10:52:38 -0500 Subject: [PATCH 3/4] Add dependencies to .pre-commit-config.yaml Added Colorama and Setuptools as dependencies to mypy in pre-commit. Co-authored-by: Hugo van Kemenade --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0c31aaff..8d9c03b7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -61,6 +61,7 @@ repos: rev: "v0.982" hooks: - id: mypy + additional_dependencies: [types-colorama, types-setuptools] args: [--pretty, --show-error-codes] exclude: ^tests/ From 4e3406b3c562cefaf0e04ac2bd247afceec93a11 Mon Sep 17 00:00:00 2001 From: Philip Date: Sun, 27 Nov 2022 20:23:47 -0500 Subject: [PATCH 4/4] updated for mypy --- src/prettytable/__init__.py | 2 +- src/prettytable/colortable.py | 9 ++++----- src/prettytable/prettytable.py | 18 +++++++++--------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/prettytable/__init__.py b/src/prettytable/__init__.py index badac567..d0f5adc7 100644 --- a/src/prettytable/__init__.py +++ b/src/prettytable/__init__.py @@ -49,6 +49,6 @@ import importlib.metadata as importlib_metadata except ImportError: # str: """Takes string and intelligently puts it into an ANSI escape sequence""" if s.strip() == "": diff --git a/src/prettytable/prettytable.py b/src/prettytable/prettytable.py index 18379ce1..3fcedea2 100644 --- a/src/prettytable/prettytable.py +++ b/src/prettytable/prettytable.py @@ -45,7 +45,7 @@ from html.parser import HTMLParser from typing import Any -import wcwidth +import wcwidth # type: ignore # hrule styles FRAME = 0 @@ -134,8 +134,8 @@ def __init__(self, field_names=None, **kwargs) -> None: self.encoding = kwargs.get("encoding", "UTF-8") # Data - self._field_names = [] - self._rows = [] + self._field_names: list[str] = [] + self._rows: list[list] = [] self.align = {} self.valign = {} self.max_width = {} @@ -147,7 +147,7 @@ def __init__(self, field_names=None, **kwargs) -> None: if field_names: self.field_names = field_names else: - self._widths = [] + self._widths: list[int] = [] # Options self._options = [ @@ -206,7 +206,7 @@ def __init__(self, field_names=None, **kwargs) -> None: self._start = kwargs["start"] or 0 self._end = kwargs["end"] or None self._fields = kwargs["fields"] or None - self._none_format = {} + self._none_format: dict[None, None] = {} if kwargs["header"] in (True, False): self._header = kwargs["header"] @@ -2031,7 +2031,7 @@ def get_json_string(self, **kwargs) -> str: """ options = self._get_options(kwargs) - json_options = dict(indent=4, separators=(",", ": "), sort_keys=True) + json_options: Any = dict(indent=4, separators=(",", ": "), sort_keys=True) json_options.update( {key: value for key, value in kwargs.items() if key not in options} ) @@ -2423,9 +2423,9 @@ class TableHandler(HTMLParser): def __init__(self, **kwargs) -> None: HTMLParser.__init__(self) self.kwargs = kwargs - self.tables = [] - self.last_row = [] - self.rows = [] + self.tables: list[list] = [] + self.last_row: list[str] = [] + self.rows: list[Any] = [] self.max_row_width = 0 self.active = None self.last_content = ""