diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 75ad87bf..8d9c03b7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -57,5 +57,13 @@ 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 + additional_dependencies: [types-colorama, types-setuptools] + args: [--pretty, --show-error-codes] + exclude: ^tests/ + ci: autoupdate_schedule: quarterly 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 = ""