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

dev: fix some mypy errors and switch to ruff #511

Merged
merged 22 commits into from
Nov 22, 2024
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
2 changes: 1 addition & 1 deletion .github/scripts/no_pandas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# %%
from ast import NodeVisitor, Import, ImportFrom, alias, parse
from ast import NodeVisitor, Import, ImportFrom, parse
from pathlib import Path
from os import walk

Expand Down
20 changes: 8 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
exclude: "(.*\\.svg)|(.*\\.qmd)|(.*\\.ambr)|(.*\\.csv)|(.*\\.txt)|(.*\\.json)"
exclude: "(.*\\.svg)|(.*\\.qmd)|(.*\\.ambr)|(.*\\.csv)|(.*\\.txt)|(.*\\.json)|(.*\\.ipynb)"
repos:
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.0
hooks:
- id: flake8
types:
- python
additional_dependencies:
- flake8-pyproject
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand All @@ -16,7 +16,3 @@ repos:
- id: check-yaml
args: ["--unsafe"]
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
- id: black
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
},
"editor.rulers": [100],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
},
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
Expand Down
4 changes: 2 additions & 2 deletions great_tables/_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from ._tbl_data import copy_data

if TYPE_CHECKING:
from ._gt_data import Body, Boxhead, RowGroups, Stub
from ._gt_data import Body

Check warning on line 8 in great_tables/_body.py

View check run for this annotation

Codecov / codecov/patch

great_tables/_body.py#L8

Added line #L8 was not covered by tests


def body_reassemble(body: Body, stub_df: Stub, boxhead: Boxhead) -> Body:
def body_reassemble(body: Body) -> Body:
# Note that this used to order the body based on groupings, but now that occurs in the
# renderer itself.
return body.__class__(copy_data(body.body))
2 changes: 0 additions & 2 deletions great_tables/_boxhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ def cols_label(
new_kwargs: dict[str, UnitStr | str | BaseText] = {}

for k, v in new_cases.items():

if isinstance(v, str):

unitstr_v = UnitStr.from_str(v)

if len(unitstr_v.units_str) == 1 and isinstance(unitstr_v.units_str[0], str):
Expand Down
2 changes: 0 additions & 2 deletions great_tables/_data_color/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ def _html_color(colors: list[str], alpha: int | float | None = None) -> list[str
all_hex_colors = all(_is_hex_col(colors=colors))

if not all_hex_colors:

# Translate named colors to hexadecimal values
colors = _color_name_to_hex(colors=colors)

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

for color in colors:

if _is_hex_col([color])[0]:
hex_colors.append(color)
else:
Expand Down
20 changes: 10 additions & 10 deletions great_tables/_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,28 @@
import time
import warnings
import webbrowser

from functools import partial
from http.server import HTTPServer, SimpleHTTPRequestHandler
from pathlib import Path
from typing import TYPE_CHECKING, Literal

from typing_extensions import TypeAlias

from ._utils import _try_import
from ._utils_render_latex import _render_as_latex


if TYPE_CHECKING:
# Note that as_raw_html uses methods on the GT class, not just data
from .gt import GT
from ._types import GTSelf

from selenium import webdriver
from IPython.core.interactiveshell import InteractiveShell
from selenium import webdriver

Check warning on line 20 in great_tables/_export.py

View check run for this annotation

Codecov / codecov/patch

great_tables/_export.py#L20

Added line #L20 was not covered by tests

from ._types import GTSelf
from .gt import GT

Check warning on line 23 in great_tables/_export.py

View check run for this annotation

Codecov / codecov/patch

great_tables/_export.py#L22-L23

Added lines #L22 - L23 were not covered by tests


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

def log_request(self, *args, **kwargs):
pass


class MISSING:
"""Represent a missing argument (where None has a special meaning)."""
Expand All @@ -44,10 +40,13 @@
return server


def _infer_render_target(ipy: InteractiveShell | None | MISSING = MISSING) -> str:
def _infer_render_target(
ipy: InteractiveShell | None | type = MISSING,
) -> Literal["auto", "notebook", "browser"]:
# adapted from py-htmltools
# Note that `ipy` arguments are possible return values of IPython.get_ipython()
# They are manually passed in from unit tests to validate this function.
target: Literal["auto", "notebook", "browser"]
try:
import IPython # pyright: ignore[reportUnknownVariableType]
from IPython.terminal.interactiveshell import TerminalInteractiveShell
Expand Down Expand Up @@ -392,6 +391,7 @@
driver: webdriver.Chrome, scale: float, path: str, debug: DebugDumpOptions | None
) -> None:
from io import BytesIO

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
Expand Down
Loading