Skip to content

Commit 549f668

Browse files
jrycwmachow
andauthored
dev: fix some mypy errors and switch to ruff (#511)
* Update `_body.py` * Remove unused function signatures. * Update `_export.py` * Update `_stub.py` * Remove unused import modules. * Update `_locations.py` * Update `_modify_rows.py` * Update `_tbl_data.py` * Update `_utils_render_html.py` * Update `gt.py` * Update `_utils_render_latex.py` * Update `_styles.py` * Clarify that `sides` in `CellStyleBorders` does not support `ColumnExpr`. * Update `_spanners.py` * Update `_utils_nanoplots.py` * Move `_flatten_list()` to `_utils.py` * Update `_utils.py` * Use `_flatten_list()` to deduplicate formatted cells in `_migrate_unformatted_to_output()`. * Update `_formats.py` * Update `_gt_data.py` * Refactor `ColumnAlignment` to a `TypeAlias` as the `Enum` definition is unused in the code. * Propose preserving the signatures of `__new__()` and `__init__()` in `Boxhead`. * dev: switch to ruff * dev: configure ruff for pyproject.toml and vscode * chore: format with ruff, mostly removing newlines after block start * dev: do not format ipynbs, format unused imports * chore: run ruff formatter * chore: run ruff formatter --------- Co-authored-by: Michael Chow <[email protected]>
1 parent 538fbf1 commit 549f668

38 files changed

+170
-537
lines changed

.github/scripts/no_pandas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# %%
2-
from ast import NodeVisitor, Import, ImportFrom, alias, parse
2+
from ast import NodeVisitor, Import, ImportFrom, parse
33
from pathlib import Path
44
from os import walk
55

.pre-commit-config.yaml

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
exclude: "(.*\\.svg)|(.*\\.qmd)|(.*\\.ambr)|(.*\\.csv)|(.*\\.txt)|(.*\\.json)"
1+
exclude: "(.*\\.svg)|(.*\\.qmd)|(.*\\.ambr)|(.*\\.csv)|(.*\\.txt)|(.*\\.json)|(.*\\.ipynb)"
22
repos:
3-
- repo: https://github.com/pycqa/flake8
4-
rev: 6.0.0
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
# Ruff version.
5+
rev: v0.8.0
56
hooks:
6-
- id: flake8
7-
types:
8-
- python
9-
additional_dependencies:
10-
- flake8-pyproject
7+
# Run the linter.
8+
- id: ruff
9+
# Run the formatter.
10+
- id: ruff-format
1111
- repo: https://github.com/pre-commit/pre-commit-hooks
1212
rev: v4.5.0
1313
hooks:
@@ -16,7 +16,3 @@ repos:
1616
- id: check-yaml
1717
args: ["--unsafe"]
1818
- id: check-added-large-files
19-
- repo: https://github.com/psf/black
20-
rev: 24.2.0
21-
hooks:
22-
- id: black

.vscode/settings.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
},
99
"editor.rulers": [100],
1010
"[python]": {
11-
"editor.defaultFormatter": "ms-python.black-formatter"
11+
"editor.formatOnSave": true,
12+
"editor.defaultFormatter": "charliermarsh.ruff",
13+
"editor.codeActionsOnSave": {
14+
"source.fixAll": "explicit",
15+
"source.organizeImports": "explicit"
16+
},
1217
},
1318
"python.testing.pytestArgs": ["tests"],
1419
"python.testing.unittestEnabled": false,

great_tables/_body.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
from ._tbl_data import copy_data
66

77
if TYPE_CHECKING:
8-
from ._gt_data import Body, Boxhead, RowGroups, Stub
8+
from ._gt_data import Body
99

1010

11-
def body_reassemble(body: Body, stub_df: Stub, boxhead: Boxhead) -> Body:
11+
def body_reassemble(body: Body) -> Body:
1212
# Note that this used to order the body based on groupings, but now that occurs in the
1313
# renderer itself.
1414
return body.__class__(copy_data(body.body))

great_tables/_boxhead.py

-2
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ def cols_label(
135135
new_kwargs: dict[str, UnitStr | str | BaseText] = {}
136136

137137
for k, v in new_cases.items():
138-
139138
if isinstance(v, str):
140-
141139
unitstr_v = UnitStr.from_str(v)
142140

143141
if len(unitstr_v.units_str) == 1 and isinstance(unitstr_v.units_str[0], str):

great_tables/_data_color/base.py

-2
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ def _html_color(colors: list[str], alpha: int | float | None = None) -> list[str
419419
all_hex_colors = all(_is_hex_col(colors=colors))
420420

421421
if not all_hex_colors:
422-
423422
# Translate named colors to hexadecimal values
424423
colors = _color_name_to_hex(colors=colors)
425424

@@ -509,7 +508,6 @@ def _color_name_to_hex(colors: list[str]) -> list[str]:
509508
hex_colors: list[str] = []
510509

511510
for color in colors:
512-
513511
if _is_hex_col([color])[0]:
514512
hex_colors.append(color)
515513
else:

great_tables/_export.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,28 @@
44
import time
55
import warnings
66
import webbrowser
7-
87
from functools import partial
98
from http.server import HTTPServer, SimpleHTTPRequestHandler
109
from pathlib import Path
1110
from typing import TYPE_CHECKING, Literal
11+
1212
from typing_extensions import TypeAlias
1313

1414
from ._utils import _try_import
1515
from ._utils_render_latex import _render_as_latex
1616

17-
1817
if TYPE_CHECKING:
1918
# Note that as_raw_html uses methods on the GT class, not just data
20-
from .gt import GT
21-
from ._types import GTSelf
22-
23-
from selenium import webdriver
2419
from IPython.core.interactiveshell import InteractiveShell
20+
from selenium import webdriver
21+
22+
from ._types import GTSelf
23+
from .gt import GT
2524

2625

2726
class PatchedHTTPRequestHandler(SimpleHTTPRequestHandler):
2827
"""Patched handler, which does not log requests to stderr"""
2928

30-
def log_request(self, *args, **kwargs):
31-
pass
32-
3329

3430
class MISSING:
3531
"""Represent a missing argument (where None has a special meaning)."""
@@ -44,10 +40,13 @@ def _create_temp_file_server(fname: Path) -> HTTPServer:
4440
return server
4541

4642

47-
def _infer_render_target(ipy: InteractiveShell | None | MISSING = MISSING) -> str:
43+
def _infer_render_target(
44+
ipy: InteractiveShell | None | type = MISSING,
45+
) -> Literal["auto", "notebook", "browser"]:
4846
# adapted from py-htmltools
4947
# Note that `ipy` arguments are possible return values of IPython.get_ipython()
5048
# They are manually passed in from unit tests to validate this function.
49+
target: Literal["auto", "notebook", "browser"]
5150
try:
5251
import IPython # pyright: ignore[reportUnknownVariableType]
5352
from IPython.terminal.interactiveshell import TerminalInteractiveShell
@@ -392,6 +391,7 @@ def _save_screenshot(
392391
driver: webdriver.Chrome, scale: float, path: str, debug: DebugDumpOptions | None
393392
) -> None:
394393
from io import BytesIO
394+
395395
from selenium.webdriver.common.by import By
396396
from selenium.webdriver.support import expected_conditions as EC
397397
from selenium.webdriver.support.ui import WebDriverWait

0 commit comments

Comments
 (0)