From 33c6f207bafe734d43a4d317015b358de9ab4956 Mon Sep 17 00:00:00 2001 From: Michael Niklas Date: Tue, 12 Sep 2023 22:04:33 +0200 Subject: [PATCH] replace type: ignore[attr-defined] with assert hasattr --- xarray/tests/test_plot.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index d1ee7aadc53..b0e6ff90bc7 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -1766,7 +1766,8 @@ def test_colors_np_levels(self) -> None: assert self._color_as_tuple(colors[1]) == (1.0, 0.0, 0.0) assert self._color_as_tuple(colors[2]) == (1.0, 1.0, 1.0) # the last color is now under "over" - assert self._color_as_tuple(cmap._rgba_over) == (0.0, 0.0, 1.0) # type: ignore[attr-defined] + assert hasattr(cmap, "_rgba_over") + assert self._color_as_tuple(cmap._rgba_over) == (0.0, 0.0, 1.0) def test_cmap_and_color_both(self) -> None: with pytest.raises(ValueError): @@ -2160,8 +2161,10 @@ def test_colorbar_scatter(self) -> None: fg: xplt.FacetGrid = ds.plot.scatter(x="a", y="a", row="x", hue="a") cbar = fg.cbar assert cbar is not None - assert cbar.vmin == 0 # type: ignore[attr-defined] - assert cbar.vmax == 3 # type: ignore[attr-defined] + assert hasattr(cbar, "vmin") + assert cbar.vmin == 0 + assert hasattr(cbar, "vmax") + assert cbar.vmax == 3 @pytest.mark.slow def test_empty_cell(self) -> None: @@ -2785,7 +2788,8 @@ def test_non_numeric_legend(self) -> None: axes = pc.axes assert axes is not None # should make a discrete legend - assert axes.legend_ is not None # type:ignore[attr-defined] + assert hasattr(axes, "legend_") + assert axes.legend_ is not None def test_legend_labels(self) -> None: # regression test for #4126: incorrect legend labels