@@ -829,6 +829,63 @@ def test_kwarg_splats_disallowed_in_function_call_annotations(self):
829
829
out = self .parse_function_should_fail (fn )
830
830
self .assertEqual (out , expected_error_msg )
831
831
832
+ def test_self_param_placement (self ):
833
+ expected_error_msg = (
834
+ "Error on line 0:\n "
835
+ "A 'self' parameter, if specified, must be the very first thing "
836
+ "in the parameter block.\n "
837
+ )
838
+ block = """
839
+ module foo
840
+ foo.func
841
+ a: int
842
+ self: self(type="PyObject *")
843
+ """
844
+ out = self .parse_function_should_fail (block )
845
+ self .assertEqual (out , expected_error_msg )
846
+
847
+ def test_self_param_cannot_be_optional (self ):
848
+ expected_error_msg = (
849
+ "Error on line 0:\n "
850
+ "A 'self' parameter cannot be marked optional.\n "
851
+ )
852
+ block = """
853
+ module foo
854
+ foo.func
855
+ self: self(type="PyObject *") = None
856
+ """
857
+ out = self .parse_function_should_fail (block )
858
+ self .assertEqual (out , expected_error_msg )
859
+
860
+ def test_defining_class_param_placement (self ):
861
+ expected_error_msg = (
862
+ "Error on line 0:\n "
863
+ "A 'defining_class' parameter, if specified, must either be the "
864
+ "first thing in the parameter block, or come just after 'self'.\n "
865
+ )
866
+ block = """
867
+ module foo
868
+ foo.func
869
+ self: self(type="PyObject *")
870
+ a: int
871
+ cls: defining_class
872
+ """
873
+ out = self .parse_function_should_fail (block )
874
+ self .assertEqual (out , expected_error_msg )
875
+
876
+ def test_defining_class_param_cannot_be_optional (self ):
877
+ expected_error_msg = (
878
+ "Error on line 0:\n "
879
+ "A 'defining_class' parameter cannot be marked optional.\n "
880
+ )
881
+ block = """
882
+ module foo
883
+ foo.func
884
+ cls: defining_class(type="PyObject *") = None
885
+ """
886
+ out = self .parse_function_should_fail (block )
887
+ self .assertEqual (out , expected_error_msg )
888
+
832
889
def test_unused_param (self ):
833
890
block = self .parse ("""
834
891
module foo
0 commit comments