Repository navigation
fix: build a write-only Python property from its setter alone [patch] - #171
Merged
Merged
Conversation
PythonGenerator wrote `@name.setter` for every writable property, but that decorator is an attribute of the property object the `@property` getter creates. A property with no getter therefore named something that did not exist, and defining the class raised NameError. A write-only property is now written as a `_set_name` function followed by `name = property(fset=_set_name)`, which needs no getter. A new test loads the generated module with python3, sets the property, and checks that reading it raises AttributeError. Fixes #113 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017USYdQkEy3VLP48Dd4JadP
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
PythonGenerator.GeneratePropertyDeclarationwrote@name.setterfor every writable property. That decorator is an attribute of the property object the@propertygetter creates, so when a property had no getter the class statement raisedNameError: name 'level' is not defined.A write-only property (
CanWrite && !CanRead) is now written as:Read/write and read-only properties produce the same output as before.
Tests
PythonGeneratedSourceImportsTests.WriteOnlyProperty_ImportsAndSetsgenerates a class withHasGetter = false, loads it withpython3, sets the property, checks that the setter ran, and checks that reading the property raisesAttributeError.mainwithNameError: name 'level' is not definedand passes with this change.Coder.Testsuite: 1072 passed, 0 failed.Fixes #113
🤖 Generated with Claude Code
https://claude.ai/code/session_017USYdQkEy3VLP48Dd4JadP
Generated by Claude Code