Repository navigation
bpo-30486: Allow setting cell value #1840
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
Changes from 3 commits
83b5e62
9b4cfd2
244cb7e
c5db387
02dbd0e
447cc10
b22b945
f11ace7
bd5e329
1f0ef6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,6 +93,20 @@ def f(): print(a) | |
| self.fail("shouldn't be able to read an empty cell") | ||
| a = 12 | ||
|
|
||
| def test_set_cell(self): | ||
| a = 12 | ||
| def f(): print(a) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a blocker to getting this accepted, btw, just nice to have ;-)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a good idea! |
||
| c = f.__closure__ | ||
| c[0].cell_contents = 9 | ||
| self.assertEqual(c[0].cell_contents, 9) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to check how setting and deleting |
||
| c[0].cell_contents = None | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You should test |
||
| try: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that you have copied an example from the above test, but this is too verbose. |
||
| c[0].cell_contents | ||
| except ValueError: | ||
| pass | ||
| else: | ||
| self.fail("shouldn't be able to read an empty cell") | ||
|
|
||
| def test___name__(self): | ||
| self.assertEqual(self.b.__name__, 'b') | ||
| self.b.__name__ = 'c' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,8 +140,19 @@ cell_get_contents(PyCellObject *op, void *closure) | |
| return op->ob_ref; | ||
| } | ||
|
|
||
| int | ||
| cell_set_contents(PyCellObject *op, PyObject *obj) | ||
| { | ||
| if (obj == Py_None) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None is a legal value for the cell value. |
||
| obj = NULL; | ||
| Py_XINCREF(obj); | ||
| Py_XSETREF(op->ob_ref, obj); | ||
| return 0; | ||
| } | ||
|
|
||
| static PyGetSetDef cell_getsetlist[] = { | ||
| {"cell_contents", (getter)cell_get_contents, NULL}, | ||
| {"cell_contents", (getter)cell_get_contents, | ||
| (setter)cell_set_contents, NULL}, | ||
| {NULL} /* sentinel */ | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
__closure__attribute is not writable. The undocumentedcell_contentsattribute of__closure__elements is writable.