FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add index property to _Row and _Column by ChrisJr404 · Pull Request #1599 · python-openxml/python-docx · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
22 changes: 11 additions & 11 deletions src/docx/table.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,12 @@ def __init__(self, gridCol: CT_TblGridCol, parent: TableParent):
@property
def cells(self) -> tuple[_Cell, ...]:
"""Sequence of |_Cell| instances corresponding to cells in this column."""
return tuple(self.table.column_cells(self._index))
return tuple(self.table.column_cells(self.index))

@property
def index(self) -> int:
"""Index of this column in the table, starting from zero."""
return self._gridCol.gridCol_idx

@property
def table(self) -> Table:
Expand All @@ -338,11 +343,6 @@ def width(self) -> Length | None:
def width(self, value: Length | None):
self._gridCol.w = value

@property
def _index(self):
"""Index of this column in its table, starting from zero."""
return self._gridCol.gridCol_idx


class _Columns(Parented):
"""Sequence of |_Column| instances corresponding to the columns in a table.
Expand Down Expand Up @@ -471,6 +471,11 @@ def grid_cols_before(self) -> int:
"""
return self._tr.grid_before

@property
def index(self) -> int:
"""Index of this row in the table, starting from zero."""
return self._tr.tr_idx

@property
def height(self) -> Length | None:
"""Return a |Length| object representing the height of this cell, or |None| if
Expand Down Expand Up @@ -498,11 +503,6 @@ def table(self) -> Table:
"""Reference to the |Table| object this row belongs to."""
return self._parent.table

@property
def _index(self) -> int:
"""Index of this row in its table, starting from zero."""
return self._tr.tr_idx


class _Rows(Parented):
"""Sequence of |_Row| objects corresponding to the rows in a table.
Expand Down
8 changes: 4 additions & 4 deletions tests/test_table.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,13 @@ def it_knows_its_index_in_table_to_help(self, table_: Mock):
tbl = cast(CT_Tbl, element("w:tbl/w:tblGrid/(w:gridCol,w:gridCol,w:gridCol)"))
gridCol = tbl.tblGrid.gridCol_lst[1]
column = _Column(gridCol, table_)
assert column._index == 1
assert column.index == 1

# fixtures -------------------------------------------------------

@pytest.fixture
def _index_prop_(self, request: FixtureRequest):
return property_mock(request, _Column, "_index")
return property_mock(request, _Column, "index")

@pytest.fixture
def parent_(self, request: FixtureRequest):
Expand Down Expand Up @@ -826,13 +826,13 @@ def it_provides_access_to_the_table_it_belongs_to(self, parent_: Mock, table_: M
def it_knows_its_index_in_table_to_help(self, parent_: Mock):
tbl = element("w:tbl/(w:tr,w:tr,w:tr)")
row = _Row(cast(CT_Row, tbl[1]), parent_)
assert row._index == 1
assert row.index == 1

# fixtures -------------------------------------------------------

@pytest.fixture
def _index_prop_(self, request: FixtureRequest):
return property_mock(request, _Row, "_index")
return property_mock(request, _Row, "index")

@pytest.fixture
def parent_(self, request: FixtureRequest):
Expand Down

Back | FazBrowse Home | New Git URL