Skip to content

Fix new_window argument typing in Session #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libtmux/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def new_window(
self,
window_name: str | None = None,
*,
start_directory: None = None,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider accepting PathLike inputs for start_directory

Update the annotation to os.PathLike[str] | str | None (or Path | str | None) and convert to str afterward so callers can pass pathlib.Path or other PathLike objects.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds good. But it would change the public API. I'll need input on that @tony 😃

start_directory: str | None = None,
attach: bool = False,
window_index: str = "",
window_shell: str | None = None,
Expand Down Expand Up @@ -677,7 +677,7 @@ def new_window(

window_args += ("-P",)

if start_directory:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Explicit None check changes behavior for empty strings

An empty string now passes and becomes ./. To skip empty values, revert to if start_directory: or explicitly require non-empty paths.

if start_directory is not None:
# 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}",)
Expand Down