From 2f11a06adc19962d48cc446468df146bb66fdb51 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Mon, 26 May 2025 05:20:20 -0500 Subject: [PATCH 1/2] types: Add `StrPath` --- src/libtmux/_internal/types.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/libtmux/_internal/types.py 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]" From 7f96abbaf2890bfeb260d720eaaa8dcdb510413e Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Mon, 26 May 2025 05:21:46 -0500 Subject: [PATCH 2/2] types(server[new_window]) Use `StrPath` for `start_directory` --- src/libtmux/session.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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}",)