Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated pre-commit with mypy #218

Merged
merged 5 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
phershbe marked this conversation as resolved.
Show resolved Hide resolved
phershbe marked this conversation as resolved.
Show resolved Hide resolved
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] = {}
phershbe marked this conversation as resolved.
Show resolved Hide resolved

if kwargs["header"] in (True, False):
self._header = kwargs["header"]
Expand Down Expand Up @@ -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)
phershbe marked this conversation as resolved.
Show resolved Hide resolved
json_options.update(
{key: value for key, value in kwargs.items() if key not in options}
)
Expand Down Expand Up @@ -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] = []
phershbe marked this conversation as resolved.
Show resolved Hide resolved
self.last_row: list[str] = []
self.rows: list[Any] = []
phershbe marked this conversation as resolved.
Show resolved Hide resolved
self.max_row_width = 0
self.active = None
self.last_content = ""
Expand Down