py-pdf / fpdf2

Simple PDF generation for Python
https://py-pdf.github.io/fpdf2/
GNU Lesser General Public License v3.0
1.07k stars 246 forks source link

Wrong signature for `pdf.table` #1194

Closed AlexanderPodorov closed 3 months ago

AlexanderPodorov commented 3 months ago

Describe the bug

Error details See example from documentation:

with pdf.table(TABLE_DATA, num_heading_rows=2):
    pass

However parameter num_heading_rows is not presented in pdf.table signature causing type warnings.

Environment Please provide the following information:

gmischler commented 3 months ago

Hi @AlexanderPodorov ,

pdf.table() just passes all provided arguments to table.Table(), which does include a num_heading_rows parameter. That arrangement works perfectly fine (the relevant code hasn't been changed for about a year).

Can you please copy the exact wording of the "type warnings" you get from using it? That is really the most important information that might enable us to say anything useful about your results, and possibly fix any actual problems.

AlexanderPodorov commented 3 months ago

Hi @gmischler , Sorry about not being specific. It works well in runtime, but does not pass type checking. As far as I noticed typeshed includes type stubs for fpdf2 and signature for pdf.table() is not correct. See the signature: https://github.com/python/typeshed/blob/6220c20d9360b12e2287511587825217eec3e5b5/stubs/fpdf2/fpdf/fpdf.pyi#L569-L584 num_heading_rows is missing here. Just found another issue: text_align: str | Align = "JUSTIFY", does not accept tuple[str, ...] usage, which is used in the docs, e.g.:

with pdf.table(text_align=("CENTER", "CENTER", "RIGHT", "LEFT")) as table:
    ...
gmischler commented 3 months ago

If typeshed produces nonsensical warnings about our code, why do you think this is our responsibility? This "issue" really is a non-issue. Closing now.

Of course, if you find type hints here in this repository that don't match what the code actually accepts, feel free to submit a PR with an improvement.

AlexanderPodorov commented 3 months ago

Sorry about that! I will file an issue for the typeshed.