diff --git a/src/libtmux/_internal/types.py b/src/libtmux/_internal/types.py new file mode 100644 index 000000000..7e9953dfe --- /dev/null +++ b/src/libtmux/_internal/types.py @@ -0,0 +1,19 @@ +"""Internal type annotations. + +Notes +----- +:class:`StrPath` and :class:`StrOrBytesPath` is based on `typeshed's`_. + +.. _typeshed's: https://github.com/python/typeshed/blob/5ff32f3/stdlib/_typeshed/__init__.pyi#L176-L179 +""" # E501 + +from __future__ import annotations + +import typing as t + +if t.TYPE_CHECKING: + from os import PathLike + + from typing_extensions import TypeAlias + +StrPath: TypeAlias = "str | PathLike[str]" diff --git a/src/libtmux/session.py b/src/libtmux/session.py index 1b8af4563..1016d423c 100644 --- a/src/libtmux/session.py +++ b/src/libtmux/session.py @@ -34,6 +34,7 @@ import sys import types + from libtmux._internal.types import StrPath from libtmux.common import tmux_cmd if sys.version_info >= (3, 11): @@ -587,7 +588,7 @@ def new_window( self, window_name: str | None = None, *, - start_directory: str | None = None, + start_directory: StrPath | None = None, attach: bool = False, window_index: str = "", window_shell: str | None = None, @@ -677,7 +678,8 @@ def new_window( window_args += ("-P",) - if start_directory is not None: + # Catch empty string and default (`None`) + if start_directory and isinstance(start_directory, str): # as of 2014-02-08 tmux 1.9-dev doesn't expand ~ in new-window -c. start_directory = pathlib.Path(start_directory).expanduser() window_args += (f"-c{start_directory}",)