@@ -766,28 +766,29 @@ def assertFullArgSpecEquals(self, routine, args_e, varargs_e=None,
766766 posonlyargs_e = [], kwonlyargs_e = [],
767767 kwonlydefaults_e = None ,
768768 ann_e = {}, formatted = None ):
769- args , varargs , varkw , defaults , posonlyargs , kwonlyargs , kwonlydefaults , ann = \
770- inspect .getfullargspec (routine )
769+ with self .assertWarns (DeprecationWarning ):
770+ args , varargs , varkw , defaults , kwonlyargs , kwonlydefaults , ann = \
771+ inspect .getfullargspec (routine )
771772 self .assertEqual (args , args_e )
772773 self .assertEqual (varargs , varargs_e )
773774 self .assertEqual (varkw , varkw_e )
774775 self .assertEqual (defaults , defaults_e )
775- self .assertEqual (posonlyargs , posonlyargs_e )
776776 self .assertEqual (kwonlyargs , kwonlyargs_e )
777777 self .assertEqual (kwonlydefaults , kwonlydefaults_e )
778778 self .assertEqual (ann , ann_e )
779779 if formatted is not None :
780780 with self .assertWarns (DeprecationWarning ):
781781 self .assertEqual (inspect .formatargspec (args , varargs , varkw , defaults ,
782- posonlyargs , kwonlyargs ,
783- kwonlydefaults , ann ),
782+ kwonlyargs , kwonlydefaults , ann ),
784783 formatted )
785784
786785 def test_getargspec (self ):
787786 self .assertArgSpecEquals (mod .eggs , ['x' , 'y' ], formatted = '(x, y)' )
788787
789- self .assertRaises (ValueError , self .assertArgSpecEquals ,
790- mod .spam , [])
788+ self .assertArgSpecEquals (mod .spam ,
789+ ['a' , 'b' , 'c' , 'd' , 'e' , 'f' ],
790+ 'g' , 'h' , (3 , 4 , 5 ),
791+ '(a, b, c, d=3, e=4, f=5, *g, **h)' )
791792
792793 self .assertRaises (ValueError , self .assertArgSpecEquals ,
793794 mod2 .keyworded , [])
@@ -811,25 +812,22 @@ def test_getfullargspec(self):
811812 kwonlyargs_e = ['arg' ],
812813 formatted = '(*, arg)' )
813814
814- self .assertFullArgSpecEquals (mod2 .all_markers , ['c' , 'd' ],
815- posonlyargs_e = ['a' , 'b' ],
815+ self .assertFullArgSpecEquals (mod2 .all_markers , ['a' , 'b' , 'c' , 'd' ],
816816 kwonlyargs_e = ['e' , 'f' ],
817- formatted = '(a, b, /, c, d, *, e, f)' )
817+ formatted = '(a, b, c, d, *, e, f)' )
818818
819819 self .assertFullArgSpecEquals (mod2 .all_markers_with_args_and_kwargs ,
820- ['c' , 'd' ],
821- posonlyargs_e = ['a' , 'b' ],
820+ ['a' , 'b' , 'c' , 'd' ],
822821 varargs_e = 'args' ,
823822 varkw_e = 'kwargs' ,
824823 kwonlyargs_e = ['e' , 'f' ],
825- formatted = '(a, b, /, c, d, *args, e, f, **kwargs)' )
824+ formatted = '(a, b, c, d, *args, e, f, **kwargs)' )
826825
827- self .assertFullArgSpecEquals (mod2 .all_markers_with_defaults , ['c' , 'd' ],
826+ self .assertFullArgSpecEquals (mod2 .all_markers_with_defaults , ['a' , 'b' , ' c' , 'd' ],
828827 defaults_e = (1 ,2 ,3 ),
829- posonlyargs_e = ['a' , 'b' ],
830828 kwonlyargs_e = ['e' , 'f' ],
831829 kwonlydefaults_e = {'e' : 4 , 'f' : 5 },
832- formatted = '(a, b=1, /, c=2, d=3, *, e=4, f=5)' )
830+ formatted = '(a, b=1, c=2, d=3, *, e=4, f=5)' )
833831
834832 def test_argspec_api_ignores_wrapped (self ):
835833 # Issue 20684: low level introspection API must ignore __wrapped__
@@ -877,25 +875,27 @@ def test():
877875 spam_param = inspect .Parameter ('spam' , inspect .Parameter .POSITIONAL_ONLY )
878876 test .__signature__ = inspect .Signature (parameters = (spam_param ,))
879877
880- self .assertFullArgSpecEquals (test , [], posonlyargs_e = [ 'spam' ], formatted = '(spam, / )' )
878+ self .assertFullArgSpecEquals (test , ['spam' ], formatted = '(spam)' )
881879
882880 def test_getfullargspec_signature_annos (self ):
883881 def test (a :'spam' ) -> 'ham' : pass
884- spec = inspect .getfullargspec (test )
882+ with self .assertWarns (DeprecationWarning ):
883+ spec = inspect .getfullargspec (test )
885884 self .assertEqual (test .__annotations__ , spec .annotations )
886885
887886 def test (): pass
888- spec = inspect .getfullargspec (test )
887+ with self .assertWarns (DeprecationWarning ):
888+ spec = inspect .getfullargspec (test )
889889 self .assertEqual (test .__annotations__ , spec .annotations )
890890
891891 @unittest .skipIf (MISSING_C_DOCSTRINGS ,
892892 "Signature information for builtins requires docstrings" )
893893 def test_getfullargspec_builtin_methods (self ):
894- self .assertFullArgSpecEquals (_pickle .Pickler .dump , [],
895- posonlyargs_e = [ 'self' , 'obj' ], formatted = '(self, obj, / )' )
894+ self .assertFullArgSpecEquals (_pickle .Pickler .dump , ['self' , 'obj' ],
895+ formatted = '(self, obj)' )
896896
897- self .assertFullArgSpecEquals (_pickle .Pickler (io .BytesIO ()).dump , [],
898- posonlyargs_e = [ 'self' , 'obj' ], formatted = '(self, obj, / )' )
897+ self .assertFullArgSpecEquals (_pickle .Pickler (io .BytesIO ()).dump , ['self' , 'obj' ],
898+ formatted = '(self, obj)' )
899899
900900 self .assertFullArgSpecEquals (
901901 os .stat ,
@@ -910,7 +910,8 @@ def test_getfullargspec_builtin_methods(self):
910910 def test_getfullargspec_builtin_func (self ):
911911 import _testcapi
912912 builtin = _testcapi .docstring_with_signature_with_defaults
913- spec = inspect .getfullargspec (builtin )
913+ with self .assertWarns (DeprecationWarning ):
914+ spec = inspect .getfullargspec (builtin )
914915 self .assertEqual (spec .defaults [0 ], 'avocado' )
915916
916917 @cpython_only
@@ -919,17 +920,20 @@ def test_getfullargspec_builtin_func(self):
919920 def test_getfullargspec_builtin_func_no_signature (self ):
920921 import _testcapi
921922 builtin = _testcapi .docstring_no_signature
922- with self .assertRaises (TypeError ):
923- inspect .getfullargspec (builtin )
923+ with self .assertWarns (DeprecationWarning ):
924+ with self .assertRaises (TypeError ):
925+ inspect .getfullargspec (builtin )
924926
925927 def test_getfullargspec_definition_order_preserved_on_kwonly (self ):
926928 for fn in signatures_with_lexicographic_keyword_only_parameters ():
927- signature = inspect .getfullargspec (fn )
929+ with self .assertWarns (DeprecationWarning ):
930+ signature = inspect .getfullargspec (fn )
928931 l = list (signature .kwonlyargs )
929932 sorted_l = sorted (l )
930933 self .assertTrue (l )
931934 self .assertEqual (l , sorted_l )
932- signature = inspect .getfullargspec (unsorted_keyword_only_parameters_fn )
935+ with self .assertWarns (DeprecationWarning ):
936+ signature = inspect .getfullargspec (unsorted_keyword_only_parameters_fn )
933937 l = list (signature .kwonlyargs )
934938 self .assertEqual (l , unsorted_keyword_only_parameters )
935939
@@ -1386,8 +1390,9 @@ class TestGetcallargsFunctions(unittest.TestCase):
13861390 def assertEqualCallArgs (self , func , call_params_string , locs = None ):
13871391 locs = dict (locs or {}, func = func )
13881392 r1 = eval ('func(%s)' % call_params_string , None , locs )
1389- r2 = eval ('inspect.getcallargs(func, %s)' % call_params_string , None ,
1390- locs )
1393+ with self .assertWarns (DeprecationWarning ):
1394+ r2 = eval ('inspect.getcallargs(func, %s)' % call_params_string , None ,
1395+ locs )
13911396 self .assertEqual (r1 , r2 )
13921397
13931398 def assertEqualException (self , func , call_param_string , locs = None ):
@@ -1399,8 +1404,9 @@ def assertEqualException(self, func, call_param_string, locs=None):
13991404 else :
14001405 self .fail ('Exception not raised' )
14011406 try :
1402- eval ('inspect.getcallargs(func, %s)' % call_param_string , None ,
1403- locs )
1407+ with self .assertWarns (DeprecationWarning ):
1408+ eval ('inspect.getcallargs(func, %s)' % call_param_string , None ,
1409+ locs )
14041410 except Exception as e :
14051411 ex2 = e
14061412 else :
@@ -1558,14 +1564,16 @@ def test_errors(self):
15581564 def f5 (* , a ): pass
15591565 with self .assertRaisesRegex (TypeError ,
15601566 'missing 1 required keyword-only' ):
1561- inspect .getcallargs (f5 )
1567+ with self .assertWarns (DeprecationWarning ):
1568+ inspect .getcallargs (f5 )
15621569
15631570
15641571 # issue20817:
15651572 def f6 (a , b , c ):
15661573 pass
15671574 with self .assertRaisesRegex (TypeError , "'a', 'b' and 'c'" ):
1568- inspect .getcallargs (f6 )
1575+ with self .assertWarns (DeprecationWarning ):
1576+ inspect .getcallargs (f6 )
15691577
15701578 # bpo-33197
15711579 with self .assertRaisesRegex (ValueError ,
0 commit comments