Skip to content

annotate pathlib.Path.{owner,group,is_mount} on windows #13613

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

Merged
merged 2 commits into from
Mar 11, 2025

Conversation

jorenham
Copy link
Contributor

This basically is uses the same partytrick as #13602, but applied to Never itself, and leads to similar issues in the NumPy stubs, as well.

Attempting to use these methods on windows <3.12 will now be reported by mypy as a classic misc, instead of attr-defined, which IMO was a bit more confusing.
Pyright users won't even notice the difference — they'll still be confronted with very same reportAttributeAccessIssue and reportUnknownMemberType power chords.

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

Interesting approach. I like this, because it reduces the number of stubtest ignore entries, while documenting the problem better in the stub itself. But wouldn't it be better to just annotate these methods to return NoReturn instead of using the self: Never hack?

@jorenham
Copy link
Contributor Author

jorenham commented Mar 11, 2025

But wouldn't it be better to just annotate these methods to return NoReturn instead of using the self: Never hack?

I thought about that, and I've tried it before. But this has three problems:

  1. Mypy doesn't report it as invalid
  2. Mypy won't analyze the code than "comes after" it, but doesn't tell that, which is problematic when type-testing it using .pyi
  3. Subclasses won't be able to override this method as that would violate LSP (only relevant on Python 3.12 in this case)

@srittau srittau merged commit 28106bc into python:main Mar 11, 2025
55 checks passed
@jorenham jorenham deleted the pathlib.Path-win32 branch March 11, 2025 18:34
mmingyu pushed a commit to mmingyu/typeshed that referenced this pull request May 16, 2025
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