@@ -127,3 +127,55 @@ def f(x: int) -> int:
127127 func_node , * _ = mod .nodes_of_class (nodes .FunctionDef )
128128 with self .assertNoMessages ():
129129 self .checker .visit_functiondef (func_node )
130+
131+ def test_valid_multi_line_preconditions (self ) -> None :
132+ src = """
133+ def f(data: list, threshold: int) -> int:
134+ '''Return list length of a positive integer array
135+
136+ Preconditions:
137+ - len(data) > 0 and \
138+ all(isinstance(x, int) for x in data) and \
139+ threshold >= 0
140+ - data != []
141+ '''
142+ return len(data)
143+ """
144+
145+ mod = parse (src )
146+ func_node , * _ = mod .nodes_of_class (nodes .FunctionDef )
147+ with self .assertNoMessages ():
148+ self .checker .visit_functiondef (func_node )
149+
150+ def test_invalid_multi_line_preconditions (self ) -> None :
151+ src = """
152+ def f(data: list, threshold: int) -> int:
153+ '''Return list length of a positive integer array
154+
155+ Preconditions:
156+ - len(data) > 0 and \
157+ all(isinstance(x, int) for x in data) and \
158+ threshold > = 0
159+ - data !== []
160+ '''
161+ return len(data)
162+ """
163+
164+ mod = parse (src )
165+ func_node , * _ = mod .nodes_of_class (nodes .FunctionDef )
166+ with self .assertAddsMessages (
167+ pylint .testutils .MessageTest (
168+ msg_id = "invalid-precondition-syntax" ,
169+ node = func_node ,
170+ args = (
171+ "len(data) > 0 and all(isinstance(x, int) for x in data) and threshold > = 0" ,
172+ ),
173+ ),
174+ pylint .testutils .MessageTest (
175+ msg_id = "invalid-precondition-syntax" ,
176+ node = func_node ,
177+ args = ("data !== []" ,),
178+ ),
179+ ignore_position = True ,
180+ ):
181+ self .checker .visit_functiondef (func_node )
0 commit comments