1+ from __future__ import annotations
2+
13import re
4+ import typing
5+ from typing import Any , Callable , TypeVar
26
37import numpy as np
48import pytest
711from matplotlib import _api
812
913
14+ if typing .TYPE_CHECKING :
15+ from typing_extensions import Self
16+
17+ T = TypeVar ('T' )
18+
19+
1020@pytest .mark .parametrize ('target,test_shape' ,
1121 [((None , ), (1 , 3 )),
1222 ((None , 3 ), (1 ,)),
1323 ((None , 3 ), (1 , 2 )),
1424 ((1 , 5 ), (1 , 9 )),
1525 ((None , 2 , None ), (1 , 3 , 1 ))
1626 ])
17- def test_check_shape (target , test_shape ):
27+ def test_check_shape (target : tuple [int | None , ...],
28+ test_shape : tuple [int , ...]) -> None :
1829 error_pattern = (f"^'aardvark' must be { len (target )} D.*" +
1930 re .escape (f'has shape { test_shape } ' ))
2031 data = np .zeros (test_shape )
2132 with pytest .raises (ValueError , match = error_pattern ):
2233 _api .check_shape (target , aardvark = data )
2334
2435
25- def test_classproperty_deprecation ():
36+ def test_classproperty_deprecation () -> None :
2637 class A :
2738 @_api .deprecated ("0.0.0" )
2839 @_api .classproperty
29- def f (cls ) :
40+ def f (cls : Self ) -> None :
3041 pass
3142 with pytest .warns (mpl .MatplotlibDeprecationWarning ):
3243 A .f
@@ -35,12 +46,12 @@ def f(cls):
3546 a .f
3647
3748
38- def test_deprecate_privatize_attribute ():
49+ def test_deprecate_privatize_attribute () -> None :
3950 class C :
40- def __init__ (self ): self ._attr = 1
41- def _meth (self , arg ) : return arg
42- attr = _api .deprecate_privatize_attribute ("0.0" )
43- meth = _api .deprecate_privatize_attribute ("0.0" )
51+ def __init__ (self ) -> None : self ._attr = 1
52+ def _meth (self , arg : T ) -> T : return arg
53+ attr : int = _api .deprecate_privatize_attribute ("0.0" )
54+ meth : Callable = _api .deprecate_privatize_attribute ("0.0" )
4455
4556 c = C ()
4657 with pytest .warns (mpl .MatplotlibDeprecationWarning ):
@@ -53,31 +64,31 @@ def _meth(self, arg): return arg
5364 assert c .meth (42 ) == 42
5465
5566
56- def test_delete_parameter ():
67+ def test_delete_parameter () -> None :
5768 @_api .delete_parameter ("3.0" , "foo" )
58- def func1 (foo = None ):
69+ def func1 (foo : Any = None ) -> None :
5970 pass
6071
6172 @_api .delete_parameter ("3.0" , "foo" )
62- def func2 (** kwargs ) :
73+ def func2 (** kwargs : Any ) -> None :
6374 pass
6475
65- for func in [func1 , func2 ]:
76+ for func in [func1 , func2 ]: # type: ignore[list-item]
6677 func () # No warning.
6778 with pytest .warns (mpl .MatplotlibDeprecationWarning ):
6879 func (foo = "bar" )
6980
70- def pyplot_wrapper (foo = _api .deprecation ._deprecated_parameter ):
81+ def pyplot_wrapper (foo : Any = _api .deprecation ._deprecated_parameter ) -> None :
7182 func1 (foo )
7283
7384 pyplot_wrapper () # No warning.
7485 with pytest .warns (mpl .MatplotlibDeprecationWarning ):
7586 func (foo = "bar" )
7687
7788
78- def test_make_keyword_only ():
89+ def test_make_keyword_only () -> None :
7990 @_api .make_keyword_only ("3.0" , "arg" )
80- def func (pre , arg , post = None ):
91+ def func (pre : Any , arg : Any , post : Any = None ) -> None :
8192 pass
8293
8394 func (1 , arg = 2 ) # Check that no warning is emitted.
@@ -88,14 +99,16 @@ def func(pre, arg, post=None):
8899 func (1 , 2 , 3 )
89100
90101
91- def test_deprecation_alternative ():
102+ def test_deprecation_alternative () -> None :
92103 alternative = "`.f1`, `f2`, `f3(x) <.f3>` or `f4(x)<f4>`"
93104 @_api .deprecated ("1" , alternative = alternative )
94- def f ():
105+ def f () -> None :
95106 pass
107+ if f .__doc__ is None :
108+ pytest .skip ('Documentation is disabled' )
96109 assert alternative in f .__doc__
97110
98111
99- def test_empty_check_in_list ():
112+ def test_empty_check_in_list () -> None :
100113 with pytest .raises (TypeError , match = "No argument to check!" ):
101114 _api .check_in_list (["a" ])
0 commit comments