brechtm / rinohtype

The Python document processor
http://www.mos6581.org/rinohtype
GNU Affero General Public License v3.0
506 stars 61 forks source link

Assert in flowable.py - Caused by long class name processed by autodoc #435

Open BobDenny opened 1 month ago

BobDenny commented 1 month ago

Is there an existing issue for this?

Sphinx or rinoh output

Exception occurred:
  File "C:\Users\rdenn\AppData\Roaming\Python\Python311\site-packages\rinoh\flowable.py", line 297, in flow_inner
    assert container.advance2(padding_border_bottom)
AssertionError

Source files

Too complicated. I'm getting the above exception when processing a large package with API defs processed by autodoc/napoleon. I narrowed it down to this;

def DestinationSideOfPier(self, RightAscension: float, Declination: float) -> PierSide:

which is rendered by autodoc. By changing the DestinationSideOfPier to Yo in that one place, the entire document (loads of classes and property/method defs) renders in Rinoh. I'm a bit overwhelmed by all of the Element Styling info in the manual. I know padding_border_bottom is an element style, and I looked in flowable.py but it's way above my head. It seems that that method name is longer than expected. But there are so many layers to this....

Is this a bug, a limitation, or is there a possible solution that I can implement here?

Versions

rinohtype 0.5.5 (2024-07-13)
Sphinx 7.2.6
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]
Windows-10-10.0.19045-SP0
BobDenny commented 1 month ago

Additional info: It turns out that changing the [VARIABLES] serif_typeface, [default: Paragraph] font_size, or letting them default (comment out) will change where the error occurs (thermometer during rendering), or in some cases allow the document to render successfully. Always the same error though:

assert container.advance2(padding_border_bottom)

I think I need to understand what can set up the condtions for that specific error. I should mention this behavior is identical on Debian Linux.

BobDenny commented 1 month ago

So many things trigger this. I unwrapped some lines to prevent multiple spaces in the rendered paragraphs. This caused the same error.

BobDenny commented 1 month ago

Brecht -- What sort of things can cause this?

Exception occurred:
  File "C:\Users\rdenn\AppData\Roaming\Python\Python311\site-packages\rinoh\flowable.py", line 297, in flow_inner
    assert container.advance2(padding_border_bottom)
AssertionError
BobDenny commented 1 month ago

This is crazy. I decided to try finding the cause of the assert error in flowable.py, line 297 (assert container.advance2(padding_border_bottom) by simply commenting it out. I thought it might help me understand what was causing rinoh to fail for me. Well, surprise, the problem vanished! I can render my giant document now, change the stylesheet settings, see those effects, etc.

I guess you can close this ticket unless you want to try to find out what conditions cause that assert to fail, and whether the assert being false can actually cause problems in the resulting document. For me, I can't find anything and I have really looked.

brechtm commented 1 month ago

I'm glad you were able to work around the issue, but of course this assert is in place for a reason: this is definitely a bug. I was refactoring the Container.advance function, but didn't yet wrap this up completely. Hence the existence of advance and advance2.