Skip to content

Commit 54d619f

Browse files
author
Steve Canny
committed
tbl: base _Cell on Parented
1 parent 5cdf3e0 commit 54d619f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

docx/table.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ def _tblPr(self):
7979
return self._tbl.tblPr
8080

8181

82-
class _Cell(object):
82+
class _Cell(Parented):
8383
"""
8484
Table cell
8585
"""
86-
def __init__(self, tc):
87-
super(_Cell, self).__init__()
86+
def __init__(self, tc, parent):
87+
super(_Cell, self).__init__(parent)
8888
self._tc = tc
8989

9090
@property
@@ -159,12 +159,12 @@ def __getitem__(self, idx):
159159
msg = "cell index [%d] is out of range" % idx
160160
raise IndexError(msg)
161161
tc = tr.tc_lst[self._col_idx]
162-
return _Cell(tc)
162+
return _Cell(tc, self)
163163

164164
def __iter__(self):
165165
for tr in self._tr_lst:
166166
tc = tr.tc_lst[self._col_idx]
167-
yield _Cell(tc)
167+
yield _Cell(tc, self)
168168

169169
def __len__(self):
170170
return len(self._tr_lst)
@@ -250,10 +250,10 @@ def __getitem__(self, idx):
250250
except IndexError:
251251
msg = "cell index [%d] is out of range" % idx
252252
raise IndexError(msg)
253-
return _Cell(tc)
253+
return _Cell(tc, self)
254254

255255
def __iter__(self):
256-
return (_Cell(tc) for tc in self._tr.tc_lst)
256+
return (_Cell(tc, self) for tc in self._tr.tc_lst)
257257

258258
def __len__(self):
259259
return len(self._tr.tc_lst)

tests/test_table.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ def it_can_replace_its_content_with_a_string_of_text(
142142
])
143143
def text_set_fixture(self, request):
144144
tc_cxml, new_text, expected_cxml = request.param
145-
cell = _Cell(element(tc_cxml))
145+
cell = _Cell(element(tc_cxml), None)
146146
expected_xml = xml(expected_cxml)
147147
return cell, new_text, expected_xml
148148

149149
@pytest.fixture
150150
def paragraphs_fixture(self):
151-
return _Cell(element('w:tc/(w:p, w:p)'))
151+
return _Cell(element('w:tc/(w:p, w:p)'), None)
152152

153153

154154
class Describe_Column(object):

0 commit comments

Comments
 (0)