diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1aea471..b24202b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,11 +9,11 @@ repos: - id: trailing-whitespace - id: end-of-file-fixer - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.16.0 + rev: v1.17.1 hooks: - id: mypy - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.11.13 + rev: v0.12.7 hooks: - id: ruff args: ["--fix", "--show-fixes"] diff --git a/labellines/core.py b/labellines/core.py index 9c8ba7a..c0872a9 100644 --- a/labellines/core.py +++ b/labellines/core.py @@ -1,5 +1,8 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import warnings -from typing import Optional, Union from datetime import timedelta import matplotlib.pyplot as plt import numpy as np @@ -17,13 +20,16 @@ from .line_label import LineLabel from .utils import maximum_bipartite_matching, normalize_xydata +if TYPE_CHECKING: + from line_label import Position + # Label line with line2D label data def labelLine( line: Line2D, - x, - label: Optional[str] = None, - align: Optional[bool] = None, + x: Position, + label: str | None = None, + align: bool | None = None, drop_label: bool = False, xoffset: float = 0, xoffset_logspace: bool = False, @@ -31,7 +37,7 @@ def labelLine( yoffset_logspace: bool = False, outline_color: str = "auto", outline_width: float = 8, - rotation: Optional[float] = None, + rotation: float | None = None, **kwargs, ): """ @@ -107,16 +113,16 @@ def labelLine( def labelLines( - lines: Optional[list[Line2D]] = None, - align: Optional[bool] = None, - xvals: Optional[Union[tuple[float, float], list[float]]] = None, + lines: list[Line2D] | None = None, + align: bool | None = None, + xvals: tuple[Position, Position] | list[Position] | None = None, drop_label: bool = False, shrink_factor: float = 0.05, - xoffsets: Union[float, list[float]] = 0, - yoffsets: Union[float, list[float]] = 0, + xoffsets: float | list[float] = 0, + yoffsets: float | list[float] = 0, outline_color: str = "auto", outline_width: float = 5, - rotation: Optional[bool] = None, + rotation: bool | None = None, **kwargs, ): """Label all lines with their respective legends. @@ -266,8 +272,9 @@ def labelLines( if not (xmin <= xv <= xmax): warnings.warn( ( - f"The value at position {i} in `xvals` is outside the range of its " - f"associated line ({xmin=}, {xmax=}, xval={xv}). " + f"The value at position {i} in `xvals` is outside the " + "range of its associated line " + f"({xmin=}, {xmax=}, xval={xv}). " "Clipping it into the allowed range." ), UserWarning, diff --git a/labellines/line_label.py b/labellines/line_label.py index b97b556..08f1ff8 100644 --- a/labellines/line_label.py +++ b/labellines/line_label.py @@ -12,7 +12,7 @@ if TYPE_CHECKING: from datetime import datetime - from typing import Any, Literal, Optional, Union + from typing import Any, Literal, Union from matplotlib.axes import Axes from matplotlib.lines import Line2D @@ -62,15 +62,15 @@ def __init__( self, line: Line2D, x: Position, - label: Optional[str] = None, - align: Optional[bool] = None, + label: str | None = None, + align: bool | None = None, xoffset: float = 0, xoffset_logspace: bool = False, yoffset: float = 0, yoffset_logspace: bool = False, - outline_color: Optional[Union[AutoLiteral, ColorLike]] = "auto", + outline_color: AutoLiteral | ColorLike | None = "auto", outline_width: float = 8, - rotation: Optional[float] = None, + rotation: float | None = None, **kwargs, ) -> None: """ diff --git a/pyproject.toml b/pyproject.toml index 643d542..cc010bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ filterwarnings = [ ] [tool.ruff.lint] -ignore = ["N802", "N806", "C901", "UP007"] +ignore = ["N802", "N806", "C901"] select = ["E", "C", "F", "UP", "B", "A", "YTT", "S", "N"]