File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -768,6 +768,43 @@ class C(Base):
768
768
assert c .y == 1
769
769
770
770
771
+ @pytest .mark .skipif (not PY2 , reason = "PY2-specific keyword-only error behavior" )
772
+ class TestKeywordOnlyAttributesOnPy2 (object ):
773
+ """
774
+ Tests for keyword-only attribute behavior on py2.
775
+ """
776
+
777
+ def test_syntax_error (self ):
778
+ """
779
+ Keyword-only attributes raise Syntax error on ``__init__`` generation.
780
+ """
781
+
782
+ with pytest .raises (SyntaxError ):
783
+
784
+ @attr .s (kw_only = True )
785
+ class ClassLevel (object ):
786
+ a = attr .ib ()
787
+
788
+ with pytest .raises (SyntaxError ):
789
+
790
+ @attr .s ()
791
+ class AttrLevel (object ):
792
+ a = attr .ib (kw_only = True )
793
+
794
+ def test_no_init (self ):
795
+ """
796
+ Keyworld-only is a no-op, not any error, if ``init=false``.
797
+ """
798
+
799
+ @attr .s (kw_only = True , init = False )
800
+ class ClassLevel (object ):
801
+ a = attr .ib ()
802
+
803
+ @attr .s (init = False )
804
+ class AttrLevel (object ):
805
+ a = attr .ib (kw_only = True )
806
+
807
+
771
808
@attr .s
772
809
class GC (object ):
773
810
@attr .s
You can’t perform that action at this time.
0 commit comments