Skip to content

reportlab - incorrect type on function parameter #14518

@egerlach

Description

@egerlach

Compare the types of the filename parameters between

def __init__(self, filename: str | IO[bytes], **kw) -> None: ...

and

def build(self, flowables: list[Flowable], filename: str | None = None, canvasmaker: _CanvasMaker = ...) -> None: ...

If we trace the use of the filename parameter through BaseDocTemplate, we go through:

  • In build(): used in the call to _startBuild()
  • In _startBuild(): is used in the call to _makeCanvas
  • In _makeCanvas(): Is used as one alternative in a parameter passed into (by default) canvas.Canvas, and the other alternative is self.filename, which is populated in BaseDocTemplate.__init__().
  • It is not used elsewhere in the call tree.

Therefore, the type of the filename parameter of BaseDocTemplate.build() should be str | IO[Bytes] | None. It also matches the type of the parameter of Canvas.__init__().

I've put a minimal test for this issue in a gist: https://gist.github.com/egerlach/f47c9722794b5d03f832aada27da2293

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions