Kozea / WeasyPrint

The awesome document factory
https://weasyprint.org
BSD 3-Clause "New" or "Revised" License
7.27k stars 688 forks source link

v62.3: `TypeError: can't multiply sequence by non-int of type 'float'` in `layout/percent.py` #2275

Open cmarqu opened 1 month ago

cmarqu commented 1 month ago

Hi,

similar to #2146, I'm getting an TypeError: can't multiply sequence by non-int of type 'float' exception in layout/percent.py:

html.write_pdf(pdf_file)
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/__init__.py", line 259, in write_pdf
      self.render(font_config, counter_style, **options)
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/__init__.py", line 216, in render
      return Document._render(self, font_config, counter_style, options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/document.py", line 262, in _render
      [Page(page_box) for page_box in page_boxes],
                                      ^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/__init__.py", line 130, in layout_document
      pages = list(make_all_pages(context, root_box, html, pages))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/page.py", line 906, in make_all_pages
      page, resume_at = remake_page(i, context, root_box, html)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/page.py", line 844, in remake_page
      page, resume_at, next_page = make_page(
                                   ^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/page.py", line 646, in make_page
      root_box, resume_at, next_page, _, _, _ = block_level_layout(
                                                ^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 59, in block_level_layout
      return block_level_layout_switch(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 75, in block_level_layout_switch
      return block_box_layout(
             ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 124, in block_box_layout
      result = block_container_layout(
               ^^^^^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 717, in block_container_layout
      next_page, new_children, new_max_lines) = _in_flow_layout(
                                                ^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 509, in _in_flow_layout
      collapsing_through, max_lines) = block_level_layout(
                                       ^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 59, in block_level_layout
      return block_level_layout_switch(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 75, in block_level_layout_switch
      return block_box_layout(
             ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 124, in block_box_layout
      result = block_container_layout(
               ^^^^^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 717, in block_container_layout
      next_page, new_children, new_max_lines) = _in_flow_layout(
                                                ^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 509, in _in_flow_layout
      collapsing_through, max_lines) = block_level_layout(
                                       ^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 59, in block_level_layout
      return block_level_layout_switch(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 75, in block_level_layout_switch
      return block_box_layout(
             ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 124, in block_box_layout
      result = block_container_layout(
               ^^^^^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 717, in block_container_layout
      next_page, new_children, new_max_lines) = _in_flow_layout(
                                                ^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 509, in _in_flow_layout
      collapsing_through, max_lines) = block_level_layout(
                                       ^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 59, in block_level_layout
      return block_level_layout_switch(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 75, in block_level_layout_switch
      return block_box_layout(
             ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 124, in block_box_layout
      result = block_container_layout(
               ^^^^^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 706, in block_container_layout
      new_footnotes, max_lines) = _linebox_layout(
                                  ^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/block.py", line 346, in _linebox_layout
      for i, (line, resume_at) in enumerate(lines_iterator):
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 38, in iter_line_boxes
      line, resume_at = get_next_linebox(
                        ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 95, in get_next_linebox
      last_letter, float_width) = split_inline_box(
                                  ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 720, in split_inline_box
      split_inline_level(
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 493, in split_inline_level
      last_letter, float_widths) = split_inline_box(
                                   ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 720, in split_inline_box
      split_inline_level(
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 493, in split_inline_level
      last_letter, float_widths) = split_inline_box(
                                   ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 720, in split_inline_box
      split_inline_level(
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 493, in split_inline_level
      last_letter, float_widths) = split_inline_box(
                                   ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 720, in split_inline_box
      split_inline_level(
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 493, in split_inline_level
      last_letter, float_widths) = split_inline_box(
                                   ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 720, in split_inline_box
      split_inline_level(
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 493, in split_inline_level
      last_letter, float_widths) = split_inline_box(
                                   ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 720, in split_inline_box
      split_inline_level(
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 493, in split_inline_level
      last_letter, float_widths) = split_inline_box(
                                   ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 720, in split_inline_box
      split_inline_level(
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 493, in split_inline_level
      last_letter, float_widths) = split_inline_box(
                                   ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 720, in split_inline_box
      split_inline_level(
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 493, in split_inline_level
      last_letter, float_widths) = split_inline_box(
                                   ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 720, in split_inline_box
      split_inline_level(
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 493, in split_inline_level
      last_letter, float_widths) = split_inline_box(
                                   ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 720, in split_inline_box
      split_inline_level(
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 493, in split_inline_level
      last_letter, float_widths) = split_inline_box(
                                   ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 784, in split_inline_box
      previous_resume_at = _break_waiting_children(
                           ^^^^^^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 635, in _break_waiting_children
      new_child, child_resume_at, _, _, _, _ = split_inline_level(
                                               ^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 493, in split_inline_level
      last_letter, float_widths) = split_inline_box(
                                   ^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 720, in split_inline_box
      split_inline_level(
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/inline.py", line 459, in split_inline_level
      resolve_percentages(box, containing_block)
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/percent.py", line 73, in resolve_percentages
      resolve_one_percentage(box, 'max_width', cb_width, main_flex_direction)
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/percent.py", line 35, in resolve_one_percentage
      percent = percentage(value, refer_to)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/__t/Python/3.12.7/x64/lib/python3.12/site-packages/weasyprint/layout/percent.py", line 21, in percentage
      return refer_to * value.value / 100
             ~~~~~~~~~^~~~~~~~~~~~~
  TypeError: can't multiply sequence by non-int of type 'float'

I haven't tried to narrow this down to a certain table or image (which I assume is the reason, because otherwise other documents with the same general styling convert just fine), but could do so if needed (with some effort). This is weasyprint==62.3 on Ubuntu 22.04.

grewn0uille commented 1 month ago

Hello!

Could you please share the related HTML/CSS?

cmarqu commented 1 month ago

I can't share them directly, but I'll try to produce a minimized example.

grewn0uille commented 1 month ago

A minimized example would be great. Else you can send them by email.

cmarqu commented 1 month ago

Here is a small example that shows the problem for me. weasyprint_issue_2275.zip