@@ -502,6 +502,15 @@ def test_getargspec(self):
502
502
'g' , 'h' , (3 , (4 , (5 ,))),
503
503
'(a, b, c, d=3, (e, (f,))=(4, (5,)), *g, **h)' )
504
504
505
+ def spam_deref (a , b , c , d = 3 , (e , (f ,))= (4 , (5 ,)), * g , ** h ):
506
+ def eggs ():
507
+ return a + b + c + d + e + f + g + h
508
+ return eggs
509
+ self .assertArgSpecEquals (spam_deref ,
510
+ ['a' , 'b' , 'c' , 'd' , ['e' , ['f' ]]],
511
+ 'g' , 'h' , (3 , (4 , (5 ,))),
512
+ '(a, b, c, d=3, (e, (f,))=(4, (5,)), *g, **h)' )
513
+
505
514
def test_getargspec_method (self ):
506
515
class A (object ):
507
516
def m (self ):
@@ -515,9 +524,15 @@ def test_getargspec_sublistofone(self):
515
524
exec 'def sublistOfOne((foo,)): return 1'
516
525
self .assertArgSpecEquals (sublistOfOne , [['foo' ]])
517
526
527
+ exec 'def sublistOfOne((foo,)): return (lambda: foo)'
528
+ self .assertArgSpecEquals (sublistOfOne , [['foo' ]])
529
+
518
530
exec 'def fakeSublistOfOne((foo)): return 1'
519
531
self .assertArgSpecEquals (fakeSublistOfOne , ['foo' ])
520
532
533
+ exec 'def sublistOfOne((foo)): return (lambda: foo)'
534
+ self .assertArgSpecEquals (sublistOfOne , ['foo' ])
535
+
521
536
522
537
def _classify_test (self , newstyle ):
523
538
"""Helper for testing that classify_class_attrs finds a bunch of
@@ -820,6 +835,23 @@ def test_errors(self):
820
835
self .assertEqualException (f3 , '1, 2' )
821
836
self .assertEqualException (f3 , '1, 2, a=1, b=2' )
822
837
838
+
839
+ class TestGetcallargsFunctionsCellVars (TestGetcallargsFunctions ):
840
+
841
+ def makeCallable (self , signature ):
842
+ """Create a function that returns its locals(), excluding the
843
+ autogenerated '.1', '.2', etc. tuple param names (if any)."""
844
+ with check_py3k_warnings (
845
+ ("tuple parameter unpacking has been removed" , SyntaxWarning ),
846
+ quiet = True ):
847
+ code = """lambda %s: (
848
+ (lambda: a+b+c+d+d+e+f+g+h), # make parameters cell vars
849
+ dict(i for i in locals().items()
850
+ if not is_tuplename(i[0]))
851
+ )[1]"""
852
+ return eval (code % signature , {'is_tuplename' : self .is_tuplename })
853
+
854
+
823
855
class TestGetcallargsMethods (TestGetcallargsFunctions ):
824
856
825
857
def setUp (self ):
@@ -857,8 +889,8 @@ def test_main():
857
889
run_unittest (
858
890
TestDecorators , TestRetrievingSourceCode , TestOneliners , TestBuggyCases ,
859
891
TestInterpreterStack , TestClassesAndFunctions , TestPredicates ,
860
- TestGetcallargsFunctions , TestGetcallargsMethods ,
861
- TestGetcallargsUnboundMethods )
892
+ TestGetcallargsFunctions , TestGetcallargsFunctionsCellVars ,
893
+ TestGetcallargsMethods , TestGetcallargsUnboundMethods )
862
894
863
895
if __name__ == "__main__" :
864
896
test_main ()
0 commit comments