Skip to content

Commit 07c724a

Browse files
committed
keep fixing types
1 parent 1f058cc commit 07c724a

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

typer/param_types.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,18 @@ def _open_cli_file(
302302
param: "TyperParameter | None" = None,
303303
ctx: Context | None = None,
304304
) -> IO[Any]:
305-
if not isinstance(value, (str, os.PathLike)):
306-
return value
305+
if hasattr(value, "read") or hasattr(value, "write"):
306+
return cast("IO[Any]", value)
307+
308+
if isinstance(value, str):
309+
path: str | os.PathLike[str] = value
310+
else:
311+
path = value
307312

308313
try:
309314
lazy = parameter_info.lazy
310315
if lazy is None:
311-
if os.fspath(value) == "-":
316+
if os.fspath(path) == "-":
312317
lazy = False
313318
elif "w" in mode:
314319
lazy = True
@@ -317,7 +322,7 @@ def _open_cli_file(
317322

318323
if lazy:
319324
lf = LazyFile(
320-
value,
325+
path,
321326
mode,
322327
parameter_info.encoding,
323328
parameter_info.errors,
@@ -330,7 +335,7 @@ def _open_cli_file(
330335
return cast("IO[Any]", lf)
331336

332337
f, should_close = open_stream(
333-
value,
338+
path,
334339
mode,
335340
parameter_info.encoding,
336341
parameter_info.errors,
@@ -345,5 +350,5 @@ def _open_cli_file(
345350

346351
return f
347352
except OSError as exc: # pragma: no cover
348-
message = f"'{format_filename(value)}': {exc.strerror}"
353+
message = f"'{format_filename(path)}': {exc.strerror}"
349354
raise BadParameter(message, ctx=ctx, param=param) from exc

0 commit comments

Comments
 (0)