Skip to content

Recursive call in Table Cell merging that causes a recursion error if the table is too big #1208

@grazzouk

Description

@grazzouk

There seems to be some recursion in the _grow_to method here that's used for table cell merging, that means that after a specific number of cells the code fails (for a single column table the max number of cells seems to be the recursion limit less 15). Is there a way around this that doesn't involve increasing the recursion limit?

Example code:

import sys
import docx


doc = docx.Document()
table = doc.add_table(984, 1)
table._cells[0].merge(table._cells[-1])
print('Merging 984 cells succeeds')

try:
    doc = docx.Document()
    table = doc.add_table(985, 1)
    table._cells[0].merge(table._cells[-1])
except RecursionError:
    print('but merging 985 cells fails')

sys.setrecursionlimit(1001)

doc = docx.Document()
table = doc.add_table(985, 1)
table._cells[0].merge(table._cells[-1])
print('unless you increase the recursion limit')

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy