@@ -766,28 +766,29 @@ def assertFullArgSpecEquals(self, routine, args_e, varargs_e=None,
766
766
posonlyargs_e = [], kwonlyargs_e = [],
767
767
kwonlydefaults_e = None ,
768
768
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 )
771
772
self .assertEqual (args , args_e )
772
773
self .assertEqual (varargs , varargs_e )
773
774
self .assertEqual (varkw , varkw_e )
774
775
self .assertEqual (defaults , defaults_e )
775
- self .assertEqual (posonlyargs , posonlyargs_e )
776
776
self .assertEqual (kwonlyargs , kwonlyargs_e )
777
777
self .assertEqual (kwonlydefaults , kwonlydefaults_e )
778
778
self .assertEqual (ann , ann_e )
779
779
if formatted is not None :
780
780
with self .assertWarns (DeprecationWarning ):
781
781
self .assertEqual (inspect .formatargspec (args , varargs , varkw , defaults ,
782
- posonlyargs , kwonlyargs ,
783
- kwonlydefaults , ann ),
782
+ kwonlyargs , kwonlydefaults , ann ),
784
783
formatted )
785
784
786
785
def test_getargspec (self ):
787
786
self .assertArgSpecEquals (mod .eggs , ['x' , 'y' ], formatted = '(x, y)' )
788
787
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)' )
791
792
792
793
self .assertRaises (ValueError , self .assertArgSpecEquals ,
793
794
mod2 .keyworded , [])
@@ -811,25 +812,22 @@ def test_getfullargspec(self):
811
812
kwonlyargs_e = ['arg' ],
812
813
formatted = '(*, arg)' )
813
814
814
- self .assertFullArgSpecEquals (mod2 .all_markers , ['c' , 'd' ],
815
- posonlyargs_e = ['a' , 'b' ],
815
+ self .assertFullArgSpecEquals (mod2 .all_markers , ['a' , 'b' , 'c' , 'd' ],
816
816
kwonlyargs_e = ['e' , 'f' ],
817
- formatted = '(a, b, /, c, d, *, e, f)' )
817
+ formatted = '(a, b, c, d, *, e, f)' )
818
818
819
819
self .assertFullArgSpecEquals (mod2 .all_markers_with_args_and_kwargs ,
820
- ['c' , 'd' ],
821
- posonlyargs_e = ['a' , 'b' ],
820
+ ['a' , 'b' , 'c' , 'd' ],
822
821
varargs_e = 'args' ,
823
822
varkw_e = 'kwargs' ,
824
823
kwonlyargs_e = ['e' , 'f' ],
825
- formatted = '(a, b, /, c, d, *args, e, f, **kwargs)' )
824
+ formatted = '(a, b, c, d, *args, e, f, **kwargs)' )
826
825
827
- self .assertFullArgSpecEquals (mod2 .all_markers_with_defaults , ['c' , 'd' ],
826
+ self .assertFullArgSpecEquals (mod2 .all_markers_with_defaults , ['a' , 'b' , ' c' , 'd' ],
828
827
defaults_e = (1 ,2 ,3 ),
829
- posonlyargs_e = ['a' , 'b' ],
830
828
kwonlyargs_e = ['e' , 'f' ],
831
829
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)' )
833
831
834
832
def test_argspec_api_ignores_wrapped (self ):
835
833
# Issue 20684: low level introspection API must ignore __wrapped__
@@ -877,25 +875,27 @@ def test():
877
875
spam_param = inspect .Parameter ('spam' , inspect .Parameter .POSITIONAL_ONLY )
878
876
test .__signature__ = inspect .Signature (parameters = (spam_param ,))
879
877
880
- self .assertFullArgSpecEquals (test , [], posonlyargs_e = [ 'spam' ], formatted = '(spam, / )' )
878
+ self .assertFullArgSpecEquals (test , ['spam' ], formatted = '(spam)' )
881
879
882
880
def test_getfullargspec_signature_annos (self ):
883
881
def test (a :'spam' ) -> 'ham' : pass
884
- spec = inspect .getfullargspec (test )
882
+ with self .assertWarns (DeprecationWarning ):
883
+ spec = inspect .getfullargspec (test )
885
884
self .assertEqual (test .__annotations__ , spec .annotations )
886
885
887
886
def test (): pass
888
- spec = inspect .getfullargspec (test )
887
+ with self .assertWarns (DeprecationWarning ):
888
+ spec = inspect .getfullargspec (test )
889
889
self .assertEqual (test .__annotations__ , spec .annotations )
890
890
891
891
@unittest .skipIf (MISSING_C_DOCSTRINGS ,
892
892
"Signature information for builtins requires docstrings" )
893
893
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)' )
896
896
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)' )
899
899
900
900
self .assertFullArgSpecEquals (
901
901
os .stat ,
@@ -910,7 +910,8 @@ def test_getfullargspec_builtin_methods(self):
910
910
def test_getfullargspec_builtin_func (self ):
911
911
import _testcapi
912
912
builtin = _testcapi .docstring_with_signature_with_defaults
913
- spec = inspect .getfullargspec (builtin )
913
+ with self .assertWarns (DeprecationWarning ):
914
+ spec = inspect .getfullargspec (builtin )
914
915
self .assertEqual (spec .defaults [0 ], 'avocado' )
915
916
916
917
@cpython_only
@@ -919,17 +920,20 @@ def test_getfullargspec_builtin_func(self):
919
920
def test_getfullargspec_builtin_func_no_signature (self ):
920
921
import _testcapi
921
922
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 )
924
926
925
927
def test_getfullargspec_definition_order_preserved_on_kwonly (self ):
926
928
for fn in signatures_with_lexicographic_keyword_only_parameters ():
927
- signature = inspect .getfullargspec (fn )
929
+ with self .assertWarns (DeprecationWarning ):
930
+ signature = inspect .getfullargspec (fn )
928
931
l = list (signature .kwonlyargs )
929
932
sorted_l = sorted (l )
930
933
self .assertTrue (l )
931
934
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 )
933
937
l = list (signature .kwonlyargs )
934
938
self .assertEqual (l , unsorted_keyword_only_parameters )
935
939
@@ -1386,8 +1390,9 @@ class TestGetcallargsFunctions(unittest.TestCase):
1386
1390
def assertEqualCallArgs (self , func , call_params_string , locs = None ):
1387
1391
locs = dict (locs or {}, func = func )
1388
1392
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 )
1391
1396
self .assertEqual (r1 , r2 )
1392
1397
1393
1398
def assertEqualException (self , func , call_param_string , locs = None ):
@@ -1399,8 +1404,9 @@ def assertEqualException(self, func, call_param_string, locs=None):
1399
1404
else :
1400
1405
self .fail ('Exception not raised' )
1401
1406
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 )
1404
1410
except Exception as e :
1405
1411
ex2 = e
1406
1412
else :
@@ -1558,14 +1564,16 @@ def test_errors(self):
1558
1564
def f5 (* , a ): pass
1559
1565
with self .assertRaisesRegex (TypeError ,
1560
1566
'missing 1 required keyword-only' ):
1561
- inspect .getcallargs (f5 )
1567
+ with self .assertWarns (DeprecationWarning ):
1568
+ inspect .getcallargs (f5 )
1562
1569
1563
1570
1564
1571
# issue20817:
1565
1572
def f6 (a , b , c ):
1566
1573
pass
1567
1574
with self .assertRaisesRegex (TypeError , "'a', 'b' and 'c'" ):
1568
- inspect .getcallargs (f6 )
1575
+ with self .assertWarns (DeprecationWarning ):
1576
+ inspect .getcallargs (f6 )
1569
1577
1570
1578
# bpo-33197
1571
1579
with self .assertRaisesRegex (ValueError ,
0 commit comments