8000 gh-112205: Support `@setter` annotation from AC by corona10 · Pull Request #112922 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-112205: Support @setter annotation from AC #112922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test
  • Loading branch information
corona10 committed Dec 10, 2023
commit 323cfc0522257e9c7d3cc6106055e6e72ed28d65
24 changes: 24 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2197,6 +2197,30 @@ class Foo "" ""
expected_error = err_template.format(invalid_kind)
self.expect_failure(block, expected_error, lineno=3)

def test_invalid_getset(self):
annotations = ["@getter", "@setter"]
for annotation in annotations:
with self.subTest(annotation=annotation):
block = f"""
module foo
class Foo "" ""
{annotation}
Foo.property -> int
"""
expected_error = "neither @getter nor @setter can define return type"
self.expect_failure(block, expected_error, lineno=3)

block = f"""
module foo
class Foo "" ""
{annotation}
Foo.property
obj: int
/
"""
expected_error = "neither @getter nor @setter can define parameters"
self.expect_failure(block, expected_error, lineno=0)

def test_duplicate_coexist(self):
err = "Called @coexist twice"
block = """
Expand Down
2 changes: 1 addition & 1 deletion Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5584,7 +5584,7 @@ def state_modulename_name(self, line: str) -> None:
return_converter = None
if returns:
if self.kind in {GETTER, SETTER}:
fail("@getter / @setter can not declare return type")
fail("neither @getter nor @setter can define return type")
ast_input = f"def x() -> {returns}: pass"
try:
module_node = ast.parse(ast_input)
Expand Down
0