File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -2249,6 +2249,17 @@ class Foo "" ""
22492249 expected_error = "Cannot apply both @getter and @setter to the same function!"
22502250 self .expect_failure (block , expected_error , lineno = 3 )
22512251
2252+ def test_getset_no_class (self ):
2253+ for annotation in "@getter" , "@setter" :
2254+ with self .subTest (annotation = annotation ):
2255+ block = f"""
2256+ module m
2257+ { annotation }
2258+ m.func
2259+ """
2260+ expected_error = "@getter and @setter must be methods"
2261+ self .expect_failure (block , expected_error , lineno = 2 )
2262+
22522263 def test_duplicate_coexist (self ):
22532264 err = "Called @coexist twice"
22542265 block = """
Original file line number Diff line number Diff line change @@ -5614,6 +5614,10 @@ def state_modulename_name(self, line: str) -> None:
56145614 function_name = fields .pop ()
56155615 module , cls = self .clinic ._module_and_class (fields )
56165616
5617+ if self .kind in {GETTER , SETTER }:
5618+ if not cls :
5619+ fail ("@getter and @setter must be methods" )
5620+
56175621 self .update_function_kind (full_name )
56185622 if self .kind is METHOD_INIT and not return_converter :
56195623 return_converter = init_return_converter ()
You can’t perform that action at this time.
0 commit comments