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

Conversation

Data5tream
Copy link

@Data5tream Data5tream commented May 21, 2025

Corrects the start_directory type of the new_window method on the Session class.

Fixes #595

Summary by Sourcery

Fix the typing and conditional handling of the start_directory argument in Session.new_window to accept string paths and avoid skipping valid values.

Bug Fixes:

  • Correct start_directory annotation to str | None in Session.new_window
  • Update conditional to if start_directory is not None so empty strings aren’t misinterpreted as absent paths

Copy link

sourcery-ai bot commented May 21, 2025

Reviewer's Guide

This PR fixes the new_window method on the Session class by correcting the start_directory parameter type annotation to str | None and updating the conditional logic to explicitly check for None before expanding and passing the directory argument.

Updated Class Diagram for Session.new_window Method Signature

classDiagram
  class Session {
    +new_window(window_name: str | None, start_directory: str | None, attach: bool, window_index: str, window_shell: str | None, environment: dict[str, str] | None) Window
  }
Loading

File-Level Changes

Change Details Files
Update start_directory parameter type annotation
  • Changed default annotation from None to `str
None`
Refine conditional logic for start_directory
  • Replaced if start_directory with if start_directory is not None to allow empty paths
  • Apply pathlib.Path(...).expanduser() after explicit None check
src/libtmux/session.py

Assessment against linked issues

Issue Objective Addressed Explanation

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@CLAassistant
Copy link

CLAassistant commented May 21, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Data5tream - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -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 😃

@@ -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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect argument type in the Session class
2 participants