PRs to add messages to assertion errors or replace with TypeError
, ValueError
, etc?
#13110
Replies: 3 comments
-
Thanks for the suggestion! Ideally the assumptions leading to the assert would be updated or fixed, though this might not be possible. Perhaps we could change A |
Beta Was this translation helpful? Give feedback.
-
Different people have different opinions what
No, that would be bad. The correct syntax is this: assert len(something) == 1, "only one thing is allowed" See https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement. |
Beta Was this translation helpful? Give feedback.
-
I support @mgeier's comment above. Genreally, I believe there should only be very few asserts in the code (outside of tests of course). I've noticed that there are quite a few IMHO unnecessary guards for programming errors. These two asserts are basically unnecessary sphinx/sphinx/writers/latex.py Lines 1362 to 1365 in eb337fe If they are not there, the program will fail in the following line with "Attribute error: None object has no attribute table/width", which IMHO is almost as informative as the existing assertion in the line above. I would leave the assertions out here to make the code more readable. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Intercepting sphinx's errors is difficult (#10670). Reading sphinx's error messages is also difficult, since many come from
assert
statements. E.g. the error here:is generated from this code. Would PRs to add a message (e.g.
"reference nodes must have a TextElement (such as paragraph) as parent or contain an image node as the sole child"
) be welcome? Would converting the exception type (here to aValueError
) be welcome, or were these made assertions intentionally?Beta Was this translation helpful? Give feedback.
All reactions