@@ -514,7 +514,7 @@ var symtableTestData = []struct {
514
514
Children : Children {},
515
515
},
516
516
},
517
- }, nil , "" },
517
+ }, nil ,"" },
518
518
{"def fn(a):\n global b\n global b\n return b" , "exec" , & SymTable {
519
519
Type : ModuleBlock ,
520
520
Name : "top" ,
@@ -568,112 +568,8 @@ var symtableTestData = []struct {
568
568
},
569
569
},
570
570
}, nil , "" },
571
- {"def inner():\n print(x)\n global x\n " , "exec" , & SymTable {
572
- Type : ModuleBlock ,
573
- Name : "top" ,
574
- Lineno : 0 ,
575
- Unoptimized : optTopLevel ,
576
- Nested : false ,
577
- Free : false ,
578
- ChildFree : false ,
579
- Generator : false ,
580
- Varargs : false ,
581
- Varkeywords : false ,
582
- ReturnsValue : false ,
583
- NeedsClassClosure : false ,
584
- Varnames : []string {},
585
- Symbols : Symbols {
586
- "inner" : Symbol {
587
- Flags : DefLocal ,
588
- Scope : ScopeLocal ,
589
- },
590
- "x" : Symbol {
591
- Flags : DefGlobal ,
592
- Scope : ScopeGlobalExplicit ,
593
- },
594
- },
595
- Children : Children {
596
- & SymTable {
597
- Type : FunctionBlock ,
598
- Name : "inner" ,
599
- Lineno : 1 ,
600
- Unoptimized : 0 ,
601
- Nested : false ,
602
- Free : false ,
603
- ChildFree : false ,
604
- Generator : false ,
605
- Varargs : false ,
606
- Varkeywords : false ,
607
- ReturnsValue : false ,
608
- NeedsClassClosure : false ,
609
- Varnames : []string {},
610
- Symbols : Symbols {
611
- "print" : Symbol {
612
- Flags : DefUse ,
613
- Scope : ScopeGlobalImplicit ,
614
- },
615
- "x" : Symbol {
616
- Flags : DefGlobal | DefUse ,
617
- Scope : ScopeGlobalExplicit ,
618
- },
619
- },
620
- Children : Children {},
621
- },
622
- },
623
- }, nil , "" },
624
- {"def fn(a):\n b = 6\n global b\n b = a" , "exec" , & SymTable {
625
- Type : ModuleBlock ,
626
- Name : "top" ,
627
- Lineno : 0 ,
628
- Unoptimized : optTopLevel ,
629
- Nested : false ,
630
- Free : false ,
631
- ChildFree : false ,
632
- Generator : false ,
633
- Varargs : false ,
634
- Varkeywords : false ,
635
- ReturnsValue : false ,
636
- NeedsClassClosure : false ,
637
- Varnames : []string {},
638
- Symbols : Symbols {
639
- "b" : Symbol {
640
- Flags : DefGlobal ,
641
- Scope : ScopeGlobalExplicit ,
642
- },
643
- "fn" : Symbol {
644
- Flags : DefLocal ,
645
- Scope : ScopeLocal ,
646
- },
647
- },
648
- Children : Children {
649
- & SymTable {
650
- Type : FunctionBlock ,
651
- Name : "fn" ,
652
- Lineno : 1 ,
653
- Unoptimized : 0 ,
654
- Nested : false ,
655
- Free : false ,
656
- ChildFree : false ,
657
- Generator : false ,
658
- Varargs : false ,
659
- Varkeywords : false ,
660
- ReturnsValue : false ,
661
- NeedsClassClosure : false ,
662
- Varnames : []string {"a" },
663
- Symbols : Symbols {
664
- "a" : Symbol {
665
- Flags : DefParam | DefUse ,
666
- Scope : ScopeLocal ,
667
- },
668
- "b" : Symbol {
669
- Flags : DefGlobal | DefLocal ,
670
- Scope : ScopeGlobalExplicit ,
671
- },
672
- },
673
- Children : Children {},
674
- },
675
- },
676
- }, nil , "" },
571
+ {"def inner():\n print(x)\n global x\n " , "exec" , nil , py .SyntaxError , "name 'x' is used prior to global declaration" },
572
+ {"def fn(a):\n b = 6\n global b\n b = a" , "exec" , nil , py .SyntaxError , "name 'b' is assigned to before global declaration" },
677
573
{"def fn(a=b,c=1):\n return a+b" , "exec" , & SymTable {
678
574
Type : ModuleBlock ,
679
575
Name : "top" ,
@@ -817,154 +713,8 @@ var symtableTestData = []struct {
817
713
}, nil , "" },
818
714
{"def fn(a):\n nonlocal b\n " , "exec" , nil , py .SyntaxError , "no binding for nonlocal 'b' found" },
819
715
{"def outer():\n def inner():\n nonlocal x\n x = 2" , "exec" , nil , py .SyntaxError , "no binding for nonlocal 'x' found" },
820
- {"def outer():\n x = 1\n def inner():\n print(x)\n nonlocal x\n " , "exec" , & SymTable {
821
- Type : ModuleBlock ,
822
- Name : "top" ,
823
- Lineno : 0 ,
824
- Unoptimized : optTopLevel ,
825
- Nested : false ,
826
- Free : false ,
827
- ChildFree : true ,
828
- Generator : false ,
829
- Varargs : false ,
830
- Varkeywords : false ,
831
- ReturnsValue : false ,
832
- NeedsClassClosure : false ,
833
- Varnames : []string {},
834
- Symbols : Symbols {
835
- "outer" : Symbol {
836
- Flags : DefLocal ,
837
- Scope : ScopeLocal ,
838
- },
839
- },
840
- Children : Children {
841
- & SymTable {
842
- Type : FunctionBlock ,
843
- Name : "outer" ,
844
- Lineno : 1 ,
845
- Unoptimized : 0 ,
846
- Nested : false ,
847
- Free : false ,
848
- ChildFree : true ,
849
- Generator : false ,
850
- Varargs : false ,
851
- Varkeywords : false ,
852
- ReturnsValue : false ,
853
- NeedsClassClosure : false ,
854
- Varnames : []string {},
855
- Symbols : Symbols {
856
- "inner" : Symbol {
857
- Flags : DefLocal ,
858
- Scope : ScopeLocal ,
859
- },
860
- "x" : Symbol {
861
- Flags : DefLocal ,
862
- Scope : ScopeCell ,
863
- },
864
- },
865
- Children : Children {
866
- & SymTable {
867
- Type : FunctionBlock ,
868
- Name : "inner" ,
869
- Lineno : 3 ,
870
- Unoptimized : 0 ,
871
- Nested : true ,
872
- Free : true ,
873
- ChildFree : false ,
874
- Generator : false ,
875
- Varargs : false ,
876
- Varkeywords : false ,
877
- ReturnsValue : false ,
878
- NeedsClassClosure : false ,
879
- Varnames : []string {},
880
- Symbols : Symbols {
881
- "print" : Symbol {
882
- Flags : DefUse ,
883
- Scope : ScopeGlobalImplicit ,
884
- },
885
- "x" : Symbol {
886
- Flags : DefNonlocal | DefUse ,
887
- Scope : ScopeFree ,
888
- },
889
- },
890
- Children : Children {},
891
- },
892
- },
893
- },
894
- },
895
- }, nil , "" },
896
- {"def outer():\n x = 1\n def inner():\n x = 2\n nonlocal x" , "exec" , & SymTable {
897
- Type : ModuleBlock ,
898
- Name : "top" ,
899
- Lineno : 0 ,
900
- Unoptimized : optTopLevel ,
901
- Nested : false ,
902
- Free : false ,
903
- ChildFree : true ,
904
- Generator : false ,
905
- Varargs : false ,
906
- Varkeywords : false ,
907
- ReturnsValue : false ,
908
- NeedsClassClosure : false ,
909
- Varnames : []string {},
910
- Symbols : Symbols {
911
- "outer" : Symbol {
912
- Flags : DefLocal ,
913
- Scope : ScopeLocal ,
914
- },
915
- },
916
- Children : Children {
917
- & SymTable {
918
- Type : FunctionBlock ,
919
- Name : "outer" ,
920
- Lineno : 1 ,
921
- Unoptimized : 0 ,
922
- Nested : false ,
923
- Free : false ,
924
- ChildFree : true ,
925
- Generator : false ,
926
- Varargs : false ,
927
- Varkeywords : false ,
928
- ReturnsValue : false ,
929
- NeedsClassClosure : false ,
930
- Varnames : []string {},
931
- Symbols : Symbols {
932
- "inner" : Symbol {
933
- Flags : DefLocal ,
934
- Scope : ScopeLocal ,
935
- },
936
- "x" : Symbol {
937
- Flags : DefLocal ,
938
- Scope : ScopeCell ,
939
- },
940
- },
941
- Children : Children {
942
- & SymTable {
943
- Type : FunctionBlock ,
944
- Name : "inner" ,
945
- Lineno : 3 ,
946
- Unoptimized : 0 ,
947
- Nested : true ,
948
- Free : true ,
949
- ChildFree : false ,
950
- Generator : false ,
951
- Varargs : false ,
952
- Varkeywords : false ,
953
- ReturnsValue : false ,
954
- NeedsClassClosure : false ,
955
- Varnames : []string {},
956
- Symbols : Symbols {
957
- "x" : Symbol {
958
- Flags : DefLocal | DefNonlocal ,
959
- Scope : ScopeFree ,
960
- },
961
- },
962
- Children : Children {},
963
- },
964
- },
965
- },
966
- },
967
- }, nil , "" },
716
+ {"def outer():\n x = 1\n def inner():\n print(x)\n nonlocal x\n " , "exec" , nil , py .SyntaxError , "name 'x' is used prior to nonlocal declaration" },
717
+ {"def outer():\n x = 1\n def inner():\n x = 2\n nonlocal x" , "exec" , nil , py .SyntaxError , "name 'x' is assigned to before nonlocal declaration" },
968
718
{"def outer():\n x = 1\n def inner(x):\n nonlocal x" , "exec" , nil , py .SyntaxError , "name 'x' is parameter and nonlocal" },
969
719
{"def outer():\n x = 1\n def inner(x):\n global x" , "exec" , nil , py .SyntaxError , "name 'x' is parameter and global" },
970
720
{"def outer():\n def inner():\n global x\n nonlocal x\n " , "exec" , nil , py .SyntaxError , "name 'x' is nonlocal and global" },
0 commit comments