Skip to content

Commit

Permalink
Merge pull request #218 from phershbe/main
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Dec 7, 2022
2 parents 32e788f + 4e3406b commit 4152432
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/prettytable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
import importlib.metadata as importlib_metadata
except ImportError:
# <Python 3.7 and lower
import importlib_metadata
import importlib_metadata # type: ignore

__version__ = importlib_metadata.version(__name__)
9 changes: 4 additions & 5 deletions src/prettytable/colortable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

try:
from colorama import init
except ImportError:
# Do nothing if not installed
def init():
pass

init()
except ImportError:
pass

init()

RESET_CODE = "\x1b[0m"

Expand All @@ -34,6 +32,7 @@ def __init__(
self.junction_char = junction_char
self.junction_color = Theme.format_code(junction_color)

@staticmethod
def format_code(s: str) -> str:
"""Takes string and intelligently puts it into an ANSI escape sequence"""
if s.strip() == "":
Expand Down
18 changes: 9 additions & 9 deletions src/prettytable/prettytable.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from html.parser import HTMLParser
from typing import Any

import wcwidth
import wcwidth # type: ignore

# hrule styles
FRAME = 0
Expand Down Expand Up @@ -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 = {}
Expand All @@ -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 = [
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -2043,7 +2043,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}
)
Expand Down Expand Up @@ -2435,9 +2435,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 = ""
Expand Down

0 comments on commit 4152432

Please sign in to comment.