Skip to content

Conversation

@SudheerKovvuru
Copy link

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

AI?

  • AI was used to generate this PR

AI generated PRs may be accepted, but only if @willmcgugan has responded on an issue or discussion.

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate (see note about typos above).
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

Issue

The typing for save_html(), save_text(), and save_svg() methods is overly strict. They only accept str for the path parameter, but the underlying open() call accepts PathLike objects (like pathlib.Path).

This causes static type checkers to complain when passing valid path-like objects:

from pathlib import Path
console.save_html(Path("output.html"))  # Type error with current typing

Changes Made

Updated the type hints for the path parameter in these methods:

  • save_html(path: str, ...)save_html(path: Union[str, PathLike[str]], ...)
  • save_text(path: str, ...)save_text(path: Union[str, PathLike[str]], ...)
  • save_svg(path: str, ...)save_svg(path: Union[str, PathLike[str]], ...)

Also:

  • Added from os import PathLike import
  • Updated the corresponding docstrings to reflect the new type signature

This matches the typing used by the builtin open() function and allows users to pass pathlib.Path objects without type checker errors.

Behavior

No runtime behavior changes - the code already worked with PathLike objects since open() handles them. This is purely a typing fix to match the actual runtime behavior.

Fixes #3784

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]Typing of console.save_html is overly strict.

1 participant