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

Update mypy check for matplotlib 3.8 #1751

Open
bmcfee opened this issue Sep 15, 2023 · 1 comment
Open

Update mypy check for matplotlib 3.8 #1751

bmcfee opened this issue Sep 15, 2023 · 1 comment
Labels
testing Issues with our test design and continuous integration services

Comments

@bmcfee
Copy link
Member

bmcfee commented Sep 15, 2023

When type annotations were added in #1587 and #1632 , we had to punt on matplotlib imports:

librosa/setup.cfg

Lines 135 to 136 in 43d4427

[mypy-matplotlib.*]
ignore_missing_imports = True

Matplotlib 3.8 release notes mention that type hints are now provided for most public APIs: https://matplotlib.org/stable/users/prev_whats_new/whats_new_3.8.0.html#type-hints

Once 3.8 finishes rolling out on conda(-forge), we should be able to update the lint CI environment and remove the matplotlib skip from our setup.cfg. This will require us to bump the minimum mpl version in our CI environment spec.

@bmcfee bmcfee added the testing Issues with our test design and continuous integration services label Sep 15, 2023
@bmcfee
Copy link
Member Author

bmcfee commented Oct 3, 2023

Taking a first whack at this, failures are plentiful:

librosa/display.py:152: error: Item "None" of "Axis | _DummyAxis | _AxisWrapper | None" has no attribute
"get_data_interval"  [union-attr]
            _, dmax = self.axis.get_data_interval()
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
librosa/display.py:153: error: Item "None" of "Axis | _DummyAxis | _AxisWrapper | None" has no attribute
"get_view_interval"  [union-attr]
            vmin, vmax = self.axis.get_view_interval()
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
librosa/display.py:245: error: Item "None" of "Axis | _DummyAxis | _AxisWrapper | None" has no attribute
"get_view_interval"  [union-attr]
            vmin, vmax = self.axis.get_view_interval()
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
librosa/display.py:331: error: Item "None" of "Axis | _DummyAxis | _AxisWrapper | None" has no attribute
"get_view_interval"  [union-attr]
            vmin, vmax = self.axis.get_view_interval()
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
librosa/display.py:423: error: Item "None" of "Axis | _DummyAxis | _AxisWrapper | None" has no attribute
"get_view_interval"  [union-attr]
            vmin, vmax = self.axis.get_view_interval()
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
librosa/display.py:476: error: Item "None" of "Axis | _DummyAxis | _AxisWrapper | None" has no attribute
"get_view_interval"  [union-attr]
            vmin, vmax = self.axis.get_view_interval()
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
librosa/display.py:785: error: Unsupported operand types for <= ("float" and
"_SupportsArray[dtype[Any]]")  [operator]
                if start <= data[0] or end >= data[-1]:
                   ^
librosa/display.py:785: error: Unsupported operand types for <= ("float" and
"_NestedSequence[_SupportsArray[dtype[Any]]]")  [operator]
                if start <= data[0] or end >= data[-1]:
                   ^
librosa/display.py:785: error: Unsupported operand types for <= ("float" and "str")  [operator]
                if start <= data[0] or end >= data[-1]:
                   ^
librosa/display.py:785: error: Unsupported operand types for <= ("float" and "complex")  [operator]
                if start <= data[0] or end >= data[-1]:
                   ^
librosa/display.py:785: error: Unsupported operand types for <= ("float" and "bytes")  [operator]
                if start <= data[0] or end >= data[-1]:
                   ^
librosa/display.py:785: error: Unsupported operand types for <= ("float" and
"_NestedSequence[bool | int | float | complex | str | bytes]")  [operator]
                if start <= data[0] or end >= data[-1]:
                   ^
librosa/display.py:785: note: Right operand is of type "Any | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | str | int | float | complex | bytes | _NestedSequence[bool | int | float | complex | str | bytes]"
librosa/display.py:785: error: Value of type
"_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]"
is not indexable  [index]
                if start <= data[0] or end >= data[-1]:
                            ^~~~~~~
librosa/display.py:785: error: Unsupported operand types for >= ("float" and
"_SupportsArray[dtype[Any]]")  [operator]
                if start <= data[0] or end >= data[-1]:
                                       ^
librosa/display.py:785: error: Unsupported operand types for >= ("float" and
"_NestedSequence[_SupportsArray[dtype[Any]]]")  [operator]
                if start <= data[0] or end >= data[-1]:
                                       ^
librosa/display.py:785: error: Unsupported operand types for >= ("float" and "str")  [operator]
                if start <= data[0] or end >= data[-1]:
                                       ^
librosa/display.py:785: error: Unsupported operand types for >= ("float" and "complex")  [operator]
                if start <= data[0] or end >= data[-1]:
                                       ^
librosa/display.py:785: error: Unsupported operand types for >= ("float" and "bytes")  [operator]
                if start <= data[0] or end >= data[-1]:
                                       ^
librosa/display.py:785: error: Unsupported operand types for >= ("float" and
"_NestedSequence[bool | int | float | complex | str | bytes]")  [operator]
                if start <= data[0] or end >= data[-1]:
                                       ^
librosa/display.py:801: error: Item "None" of "Figure | SubFigure | None" has no attribute "canvas" 
[union-attr]
            ax.figure.canvas.draw_idle()
            ^~~~~~~~~~~~~~~~
librosa/display.py:1394: error: Argument 1 to "FixedLocator" has incompatible type
"ndarray[Any, dtype[floating[Any]]]"; expected "Sequence[float]"  [arg-type]
            axis.set_major_locator(mplticker.FixedLocator(np.arange(6.0)))
                                                          ^~~~~~~~~~~~~~
librosa/display.py:1401: error: Argument 1 to "FixedLocator" has incompatible type
"ndarray[Any, dtype[Any]]"; expected "Sequence[float]"  [arg-type]
                mplticker.FixedLocator(np.add.outer(12 * np.arange(10), degrees).ravel())
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
librosa/display.py:1417: error: Argument 1 to "FixedLocator" has incompatible type
"ndarray[Any, dtype[Any]]"; expected "Sequence[float]"  [arg-type]
                mplticker.FixedLocator(np.add.outer(12 * np.arange(10), degrees).ravel())
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
librosa/display.py:1431: error: Argument 1 to "FixedLocator" has incompatible type
"ndarray[Any, dtype[Any]]"; expected "Sequence[float]"  [arg-type]
                mplticker.FixedLocator(np.add.outer(12 * np.arange(10), degrees).ravel())
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
librosa/display.py:1475: error: Argument 1 to "FixedLocator" has incompatible type "ndarray[Any, Any]";
expected "Sequence[float]"  [arg-type]
            axis.set_major_locator(mplticker.FixedLocator(degrees))
                                                          ^~~~~~~
librosa/display.py:1572: error: Argument 1 to "FixedLocator" has incompatible type "ndarray[Any, Any]";
expected "Sequence[float]"  [arg-type]
                    core.interval_frequencies(
                    ^
librosa/display.py:1593: error: Argument "subs" to "LogLocator" has incompatible type
"ndarray[Any, Any]"; expected "Literal['auto', 'all'] | Sequence[float] | None"  [arg-type]
                    subs=core.interval_frequencies(
                         ^
librosa/display.py:1611: error: Argument "subs" to "LogLocator" has incompatible type
"ndarray[Any, Any]"; expected "Literal['auto', 'all'] | Sequence[float] | None"  [arg-type]
                    subs=core.interval_frequencies(
                         ^
librosa/display.py:1640: error: Argument "subs" to "LogLocator" has incompatible type
"ndarray[Any, dtype[floating[Any]]]"; expected "Literal['auto', 'all'] | Sequence[float] | None" 
[arg-type]
                mplticker.LogLocator(base=2.0, subs=2.0 ** (np.arange(1, 12) / 12.0))
                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
librosa/display.py:2058: error: Incompatible types in assignment (expression has type
"Callable[[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | float, _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | float, Sequence[bool] | None, Literal['pre', 'post', 'mid'] | None, bool, DefaultNamedArg(Any, 'data'), KwArg(Any)], PolyCollection]",
variable has type
"Callable[[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | float, _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | float, Sequence[bool] | None, bool, Literal['pre', 'post', 'mid'] | None, DefaultNamedArg(Any, 'data'), KwArg(Any)], PolyCollection]")
 [assignment]
            filler = axes.fill_betweenx
                     ^~~~~~~~~~~~~~~~~~
librosa/display.py:2060: error: Incompatible types in assignment (expression has type "YAxis", variable
has type "XAxis")  [assignment]
            dec_axis = axes.yaxis
                       ^~~~~~~~~~
librosa/display.py:2062: error: Argument "where" to "step" of "Axes" has incompatible type "str";
expected "Literal['pre', 'post', 'mid']"  [arg-type]
        (steps,) = axes.step(xdata, ydata, marker=marker, where=where, **kwargs)
                                                                ^~~~~
librosa/display.py:2072: error: Argument "step" has incompatible type "str"; expected
"Literal['pre', 'post', 'mid'] | None"  [arg-type]
            step=where,
                 ^~~~~
Found 33 errors in 1 file (checked 35 source files)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Issues with our test design and continuous integration services
Development

No branches or pull requests

1 participant