-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Milestone
Description
click.open_file(filename, …)
happily accepts a pathlib.Path
object as the filename; it only passes the value along to either click.utils.LazyFile(filename, …)
or click._compat.open_stream(filename, …)
, both of which accept pathlikes. However, open_file
's type hints indicate that filename
can only be a string, which causes type-checking errors when feeding it a Path
.
from pathlib import Path
import click
filename = Path("/some/path")
# Mypy gives the following error on the line with the call to open_file:
#
# error: Argument 1 to "open_file" has incompatible type "Path"; expected "str" [arg-type]
with click.open_file(filename) as handle:
pass
Both LazyFile
and open_stream
give their filename parameter the type types.Union[str, os.PathLike[str]]
, so that should probably be the type accepted by open_file
, too.
Environment:
- Python version: 3.12.1
- Click version: 8.1.7
Metadata
Metadata
Assignees
Labels
No labels