Skip to content

Commit 201461d

Browse files
committed
Fix failing type checks
1 parent 49b2403 commit 201461d

5 files changed

Lines changed: 21 additions & 21 deletions

File tree

docs/conf.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import importlib.metadata
34
import sys
45
from contextlib import contextmanager
56
from datetime import datetime
@@ -9,11 +10,6 @@
910

1011
from typing_extensions import Any
1112

12-
try:
13-
import importlib.metadata as importlib_metadata
14-
except ImportError:
15-
import importlib_metadata
16-
1713
try:
1814
from ridgeplot_examples import ALL_EXAMPLES
1915
except ImportError:
@@ -40,7 +36,7 @@
4036

4137
# -- Project information ---------------------------------------------------------------------------
4238

43-
metadata = importlib_metadata.metadata("ridgeplot")
39+
metadata = importlib.metadata.metadata("ridgeplot")
4440

4541
project = project_name = name = metadata["name"]
4642
author = metadata["author"]

mypy.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ plugins = numpy.typing.mypy_plugin
4242
;show_traceback = True
4343
;raise_exceptions = True
4444

45-
[mypy-importlib_metadata.*]
46-
ignore_missing_imports = True
4745
[mypy-importlib_resources.*]
4846
ignore_missing_imports = True
4947
[mypy-plotly.*]

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ filterwarnings =
5353
ignore:is_categorical_dtype.*:DeprecationWarning
5454
# Ignore pandas' missing Pyarrow dependency warning
5555
ignore:\nPyarrow will become a required dependency.*:DeprecationWarning
56+
# Ignore Plotly's Kaleido deprecation warning
57+
ignore:\nUse of plotly\.io\.kaleido\.scope.* is deprecated.*:DeprecationWarning

src/ridgeplot/_utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
from collections.abc import Collection
66
from typing import TYPE_CHECKING
77

8-
from typing_extensions import (
9-
TypeVar,
10-
)
8+
from typing_extensions import TypeVar
119

1210
if TYPE_CHECKING:
1311
from typing_extensions import Any

tests/unit/color/test_utils.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import re
34
from typing import TYPE_CHECKING, Any
45

56
import pytest
@@ -45,26 +46,31 @@ def test_to_rgb(color: Color, expected: str) -> None:
4546
("color", "expected_exception", "exception_match"),
4647
[
4748
# invalid types
48-
(1, TypeError, None),
49-
([1, 2, 3], TypeError, None),
49+
(1, TypeError, "Expected str or tuple for color, got <class 'int'> instead"),
50+
([1, 2, 3], TypeError, "Expected str or tuple for color, got <class 'list'> instead"),
5051
# invalid CSS named color
51-
("not-a-color", ValueError, None),
52+
(
53+
"not-a-color",
54+
ValueError,
55+
"color should be a tuple or a str representation of a "
56+
"hex or rgb color, got 'not-a-color' instead",
57+
),
5258
# invalid hex
53-
("#1234567890", ValueError, r"too many values to unpack \(expected 3\)"),
54-
("#ABCDEFGHIJ", ValueError, r"invalid literal for int\(\) with base 16"),
59+
("#1234567890", ValueError, "too many values to unpack (expected 3)"),
60+
("#ABCDEFGHIJ", ValueError, "invalid literal for int() with base 16"),
5561
# invalid rgb
56-
("rgb(0,0,999)", PlotlyError, r"rgb colors tuples cannot exceed 255"),
62+
("rgb(0,0,999)", PlotlyError, "rgb colors tuples cannot exceed 255"),
5763
# invalid tuple
58-
((1, 2), ValueError, r"not enough values to unpack \(expected 3, got 2\)"),
59-
((1, 2, 3, 4), ValueError, r"too many values to unpack \(expected 3\)"),
64+
((1, 2), ValueError, "not enough values to unpack (expected 3, got 2)"),
65+
((1, 2, 3, 4), ValueError, "too many values to unpack (expected 3)"),
6066
],
6167
)
6268
def test_to_rgb_fails_for_invalid_color(
6369
color: Any,
6470
expected_exception: type[Exception],
65-
exception_match: str | None,
71+
exception_match: str,
6672
) -> None:
67-
with pytest.raises(expected_exception, match=exception_match or ""):
73+
with pytest.raises(expected_exception, match=re.escape(exception_match or "^$")):
6874
to_rgb(color)
6975

7076

0 commit comments

Comments
 (0)