Skip to content
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

Fixed __eq__ for windows. #505

Merged
merged 3 commits into from
Nov 25, 2023
Merged

Fixed __eq__ for windows. #505

merged 3 commits into from
Nov 25, 2023

Conversation

m1guelperez
Copy link
Contributor

@m1guelperez m1guelperez commented Oct 23, 2023

for window in session.list_windows():
    if window.name == "test_window":
        target_window = window
        break
    if target_window == None:
        target_window = session.new_window(
            attach=True, window_name="test_window"
        )

This code failed before at if target_window == None because comparison for windows was implemented like that:

def __eq__(self, other: object) -> bool:
      assert isinstance(other, Window)
      return self.window_id == other.window_id

However, the assert seems a bit off since it is a way to strong assumption. Thus I changed it to:

def __eq__(self, other: object) -> bool:
    if not isinstance(other, Window):
        return False
    return self.window_id == other.window_id

This code now properly returns False when we compare a window with == and the condition is indeed False.

@JThoennes
Copy link

Actually, I would try to avoid negations with not and express the code like this:

def __eq__(self, other: object) -> bool:
    if isinstance(other, Window):
        return self.window_id == other.window_id
    return False

Just my two cents.

@CLAassistant
Copy link

CLAassistant commented Nov 25, 2023

CLA assistant check
All committers have signed the CLA.

Copy link

codecov bot commented Nov 25, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (4d51e53) 88.84% compared to head (bdb105f) 88.79%.

Files Patch % Lines
src/libtmux/window.py 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #505      +/-   ##
==========================================
- Coverage   88.84%   88.79%   -0.06%     
==========================================
  Files          35       35              
  Lines        3514     3515       +1     
  Branches      484      485       +1     
==========================================
- Hits         3122     3121       -1     
- Misses        284      285       +1     
- Partials      108      109       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tony
Copy link
Member

tony commented Nov 25, 2023

@m1guelperez Rebased

@JThoennes That makes sense, I will make that change.

@tony
Copy link
Member

tony commented Nov 25, 2023

@m1guelperez Can you sign the CLA?

@m1guelperez
Copy link
Contributor Author

@m1guelperez Can you sign the CLA?

Done :)

@tony tony merged commit c729584 into tmux-python:master Nov 25, 2023
@tony
Copy link
Member

tony commented Nov 25, 2023

@m1guelperez Merged

Thank you both!

@tony
Copy link
Member

tony commented Nov 26, 2023

This is live in v0.25.0

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.

4 participants