You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
frompathlibimportPathimportclickfilename=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]withclick.open_file(filename) ashandle:
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
The text was updated successfully, but these errors were encountered:
click.open_file(filename, …)
happily accepts apathlib.Path
object as the filename; it only passes the value along to eitherclick.utils.LazyFile(filename, …)
orclick._compat.open_stream(filename, …)
, both of which accept pathlikes. However,open_file
's type hints indicate thatfilename
can only be a string, which causes type-checking errors when feeding it aPath
.Both
LazyFile
andopen_stream
give their filename parameter the typetypes.Union[str, os.PathLike[str]]
, so that should probably be the type accepted byopen_file
, too.Environment:
The text was updated successfully, but these errors were encountered: