Skip to content

handle-typing#7

Closed
Kalmat wants to merge 2 commits into
masterfrom
handle-typing
Closed

handle-typing#7
Kalmat wants to merge 2 commits into
masterfrom
handle-typing

Conversation

@Kalmat

@Kalmat Kalmat commented Jul 2, 2026

Copy link
Copy Markdown
Owner

This is my attempt to propery type handle variable. Not sure if it is right.

Apart from this, you changed this:

if sys.platform != "linux":
    raise OSError(f"Cannot import {__name__} on {sys.platform}")

by this:

assert sys.platform == "linux"

but I had to revert it back because of ruff complaining: import not at top of the file

@Kalmat Kalmat requested a review from Avasam July 2, 2026 13:22
Comment thread src/pywinbox/_pywinbox_macos.py
@Avasam

Avasam commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

but I had to revert it back because of ruff complaining: import not at top of the file

The following 3 issues can be upvoted to resolve this inconsistency between mypy and Ruff:

Comment on lines +5 to +6
if sys.platform != "linux":
raise OSError(f"Cannot import {__name__} on {sys.platform}")

@Avasam Avasam Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍
I'm surprised I hadn't done this change in this repo, I think I did so everywhere else.

Anyway it's more explicit, and won't get stripped out with python -O

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Do not discard it was myself messing around with updates, pushes, PRs, new branches... I am trying to learn as fast as I can (e.g. I was completely terrified when I made this PR... it's the first time I do it, so I was really scared to break something). Thank you for your patience!

Comment on lines 37 to 38
_HandleTypeIn :TypeAlias = Union[tuple[str, str], AppKit.NSWindow, None]
_HandleTypeOut :TypeAlias = Union[_macOSNSHandle, _macOSCGHandle, None]

@Avasam Avasam Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

- _HandleTypeIn :TypeAlias = Union[tuple[str, str], AppKit.NSWindow, None]
- _HandleTypeOut :TypeAlias = Union[_macOSNSHandle, _macOSCGHandle, None]
+ _HandleTypeIn: TypeAlias = Union[tuple[str, str], AppKit.NSWindow, None]
+ _HandleTypeOut: TypeAlias = Union[_macOSNSHandle, _macOSCGHandle, None]

Have you considered using a formatter? Formatting on save can also be run by your editor (just like Ruff autofixes on save).

Options:

  1. This exact case would've been caught by https://docs.astral.sh/ruff/rules/whitespace-before-punctuation/, I haven't enabled all pycodestyle (E) rules yet (by default they're not all enabled, ref, because some are covered by the Ruff formatter, which also isn't enabled in your repos)
  2. Using the Ruff Formatter Ruff has it's own formatter (based on Black style). Since Ruff is already in the repo, you can avoid considering Black entirely (similar styles).
  3. If you don't like the Black/Ruff formatter style, autopep8 is one I liked for a long time, autopep8 is technically more of an autofixer for Flake8's pycodestyle (E) rules. So most (but not all) would be covered by option 1 anyway. (Completing and promoting autopep8 parity astral-sh/ruff#9057 (comment) for more details on which style rules have autofixes)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Unfortunately I know nothing about formatters (first time I hear about them). I will give a try to autopep8 (I have already installed and configured it on PyCharm). Thank you for your suggestion!!!

@Avasam Avasam Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If you're wondering about the separation of concerns between a linter (with autofixes) and a formatter, here's a great writeup: https://typescript-eslint.io/users/what-about-formatting/

Feel free to play around with styles of autopep8 (pydocstyle autofixes), Ruff formatter (strongly opinionated, mostly follows Black style), or yapf (literally "Yet Another Python Formatter," based on clang-format).

@Kalmat Kalmat closed this Jul 3, 2026
@Kalmat Kalmat deleted the handle-typing branch July 3, 2026 12:45
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.

2 participants