From 201461de4980d3a5dda3c504936e5f999132b3c5 Mon Sep 17 00:00:00 2001 From: Tomas Pereira de Vasconcelos Date: Fri, 29 Aug 2025 12:09:30 +0800 Subject: [PATCH 1/2] Fix failing type checks --- docs/conf.py | 8 ++------ mypy.ini | 2 -- pytest.ini | 2 ++ src/ridgeplot/_utils.py | 4 +--- tests/unit/color/test_utils.py | 26 ++++++++++++++++---------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index f04187c6..78f0d198 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,6 @@ from __future__ import annotations +import importlib.metadata import sys from contextlib import contextmanager from datetime import datetime @@ -9,11 +10,6 @@ from typing_extensions import Any -try: - import importlib.metadata as importlib_metadata -except ImportError: - import importlib_metadata - try: from ridgeplot_examples import ALL_EXAMPLES except ImportError: @@ -40,7 +36,7 @@ # -- Project information --------------------------------------------------------------------------- -metadata = importlib_metadata.metadata("ridgeplot") +metadata = importlib.metadata.metadata("ridgeplot") project = project_name = name = metadata["name"] author = metadata["author"] diff --git a/mypy.ini b/mypy.ini index 312f9b3c..7178deb1 100644 --- a/mypy.ini +++ b/mypy.ini @@ -42,8 +42,6 @@ plugins = numpy.typing.mypy_plugin ;show_traceback = True ;raise_exceptions = True -[mypy-importlib_metadata.*] -ignore_missing_imports = True [mypy-importlib_resources.*] ignore_missing_imports = True [mypy-plotly.*] diff --git a/pytest.ini b/pytest.ini index 1e2d5416..28f12a98 100644 --- a/pytest.ini +++ b/pytest.ini @@ -53,3 +53,5 @@ filterwarnings = ignore:is_categorical_dtype.*:DeprecationWarning # Ignore pandas' missing Pyarrow dependency warning ignore:\nPyarrow will become a required dependency.*:DeprecationWarning + # Ignore Plotly's Kaleido deprecation warning + ignore:\nUse of plotly\.io\.kaleido\.scope.* is deprecated.*:DeprecationWarning diff --git a/src/ridgeplot/_utils.py b/src/ridgeplot/_utils.py index 71f1882b..bcffc2b1 100644 --- a/src/ridgeplot/_utils.py +++ b/src/ridgeplot/_utils.py @@ -5,9 +5,7 @@ from collections.abc import Collection from typing import TYPE_CHECKING -from typing_extensions import ( - TypeVar, -) +from typing_extensions import TypeVar if TYPE_CHECKING: from typing_extensions import Any diff --git a/tests/unit/color/test_utils.py b/tests/unit/color/test_utils.py index b8b87b95..c43945d5 100644 --- a/tests/unit/color/test_utils.py +++ b/tests/unit/color/test_utils.py @@ -1,5 +1,6 @@ from __future__ import annotations +import re from typing import TYPE_CHECKING, Any import pytest @@ -45,26 +46,31 @@ def test_to_rgb(color: Color, expected: str) -> None: ("color", "expected_exception", "exception_match"), [ # invalid types - (1, TypeError, None), - ([1, 2, 3], TypeError, None), + (1, TypeError, "Expected str or tuple for color, got instead"), + ([1, 2, 3], TypeError, "Expected str or tuple for color, got instead"), # invalid CSS named color - ("not-a-color", ValueError, None), + ( + "not-a-color", + ValueError, + "color should be a tuple or a str representation of a " + "hex or rgb color, got 'not-a-color' instead", + ), # invalid hex - ("#1234567890", ValueError, r"too many values to unpack \(expected 3\)"), - ("#ABCDEFGHIJ", ValueError, r"invalid literal for int\(\) with base 16"), + ("#1234567890", ValueError, "too many values to unpack (expected 3)"), + ("#ABCDEFGHIJ", ValueError, "invalid literal for int() with base 16"), # invalid rgb - ("rgb(0,0,999)", PlotlyError, r"rgb colors tuples cannot exceed 255"), + ("rgb(0,0,999)", PlotlyError, "rgb colors tuples cannot exceed 255"), # invalid tuple - ((1, 2), ValueError, r"not enough values to unpack \(expected 3, got 2\)"), - ((1, 2, 3, 4), ValueError, r"too many values to unpack \(expected 3\)"), + ((1, 2), ValueError, "not enough values to unpack (expected 3, got 2)"), + ((1, 2, 3, 4), ValueError, "too many values to unpack (expected 3)"), ], ) def test_to_rgb_fails_for_invalid_color( color: Any, expected_exception: type[Exception], - exception_match: str | None, + exception_match: str, ) -> None: - with pytest.raises(expected_exception, match=exception_match or ""): + with pytest.raises(expected_exception, match=re.escape(exception_match or "^$")): to_rgb(color) From 2765c7d2a3ffd80793f93ddaab5f6e649b4d100b Mon Sep 17 00:00:00 2001 From: Tomas Pereira de Vasconcelos Date: Fri, 29 Aug 2025 12:11:22 +0800 Subject: [PATCH 2/2] Cleanup leftover from previous implementation --- tests/unit/color/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/color/test_utils.py b/tests/unit/color/test_utils.py index c43945d5..2bce06d2 100644 --- a/tests/unit/color/test_utils.py +++ b/tests/unit/color/test_utils.py @@ -70,7 +70,7 @@ def test_to_rgb_fails_for_invalid_color( expected_exception: type[Exception], exception_match: str, ) -> None: - with pytest.raises(expected_exception, match=re.escape(exception_match or "^$")): + with pytest.raises(expected_exception, match=re.escape(exception_match)): to_rgb(color)