@@ -812,6 +812,63 @@ def test_other_bizarre_things_in_annotations_fail(self):
812
812
)
813
813
self .assertEqual (s , expected_failure_message )
814
814
815
+ def test_self_param_placement (self ):
816
+ expected_error_msg = (
817
+ "Error on line 0:\n "
818
+ "A 'self' parameter, if specified, must be the very first thing "
819
+ "in the parameter block.\n "
820
+ )
821
+ block = """
822
+ module foo
823
+ foo.func
824
+ a: int
825
+ self: self(type="PyObject *")
826
+ """
827
+ out = self .parse_function_should_fail (block )
828
+ self .assertEqual (out , expected_error_msg )
829
+
830
+ def test_self_param_cannot_be_optional (self ):
831
+ expected_error_msg = (
832
+ "Error on line 0:\n "
833
+ "A 'self' parameter cannot be marked optional.\n "
834
+ )
835
+ block = """
836
+ module foo
837
+ foo.func
838
+ self: self(type="PyObject *") = None
839
+ """
840
+ out = self .parse_function_should_fail (block )
841
+ self .assertEqual (out , expected_error_msg )
842
+
843
+ def test_defining_class_param_placement (self ):
844
+ expected_error_msg = (
845
+ "Error on line 0:\n "
846
+ "A 'defining_class' parameter, if specified, must either be the "
847
+ "first thing in the parameter block, or come just after 'self'.\n "
848
+ )
849
+ block = """
850
+ module foo
851
+ foo.func
852
+ self: self(type="PyObject *")
853
+ a: int
854
+ cls: defining_class
855
+ """
856
+ out = self .parse_function_should_fail (block )
857
+ self .assertEqual (out , expected_error_msg )
858
+
859
+ def test_defining_class_param_cannot_be_optional (self ):
860
+ expected_error_msg = (
861
+ "Error on line 0:\n "
862
+ "A 'defining_class' parameter cannot be marked optional.\n "
863
+ )
864
+ block = """
865
+ module foo
866
+ foo.func
867
+ cls: defining_class(type="PyObject *") = None
868
+ """
869
+ out = self .parse_function_should_fail (block )
870
+ self .assertEqual (out , expected_error_msg )
871
+
815
872
def parse (self , text ):
816
873
c = FakeClinic ()
817
874
parser = DSLParser (c )
0 commit comments