Opened 15 years ago
Last modified 13 years ago
#1181 new Bugs
[boost.python] can modify enum value
Reported by: | Owned by: | troy d. straszheim | |
---|---|---|---|
Milestone: | To Be Determined | Component: | python USE GITHUB |
Version: | Boost 1.34.0 | Severity: | Problem |
Keywords: | enum modify | Cc: |
Description (last modified by )
I use boost 1.34.0, python 2.5.1 User can modify the enum value, But enum should be a const value(read only).
enum my_enum{my_value}; struct my_s{ enum{ my_value2 };}; void my_export { enum_< my_enum >("my_enum") .value("my_value", my_value); scope* my_s_scope = new scope(class_< my_s>("my_s", init< >())); scope().attr("my_value2") = (int)my_value2; delete my_s_scope; }
#in python module.my_enum.my_value = 1 print module.my_enum.my_value module.my_s.my_value2 = 2 print module.my_s.my_value2 # we can modify the const value. # output # 1 # 2
Change History (3)
comment:1 by , 14 years ago
Description: | modified (diff) |
---|
comment:2 by , 14 years ago
Status: | new → assigned |
---|
This seems reasonable enough, since we can use properties to make read-only attributes, but it will take some doing. As described in http://www.python.org/download/releases/2.2/descrintro/#property, "The get method won't be called when the property is accessed as a class attribute (C.x)
instead of as an instance attribute (C().x)
." This will remain a low-priority until I (or someone else -- hint, hint) figures out how to appropriately "override the __get__
operation for properties used as a class attribute" (in pure python code) as described on that page.
comment:3 by , 13 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
I have a fix for this locally, but it needs some cleanup/refactoring yet. It borrows some of the internals of class_ (specifically the metatype) to implement readonly class properties.
Please try to use the WikiFormatting rules to create readable tickets.