GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Remove pathlib.PurePath.__eq__ by hauntsaninja · Pull Request #10662 · python/typeshed

Conversation

@hauntsaninja

@hauntsaninja hauntsaninja commented Sep 4, 2023

Copy link
Copy Markdown
Collaborator

Fixes #10661

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

NMertsch and Akuli reacted with heart emoji
All reactions
  • ❤️ 2 reactions
@hauntsaninja
Remove pathlib.PurePath.__eq__
d48d4e9
Fixes python#10661
@github-actions

This comment has been minimized.

Sign in to view
@hauntsaninja

hauntsaninja commented Sep 4, 2023

Copy link
Copy Markdown
Collaborator Author

I think the primer hits here are real issues

AlexWaygood reacted with thumbs up emoji NMertsch reacted with heart emoji
All reactions
  • 👍 1 reaction
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hauntsaninja
.
7cf01aa
@hauntsaninja
hauntsaninja force-pushed the pathlib-strict-eq branch from 659aa6c to 7cf01aa Compare September 4, 2023 23:48
@github-actions

This comment has been minimized.

Sign in to view
@AlexWaygood AlexWaygood mentioned this pull request Sep 4, 2023
comparison-overlap not triggered for pathlib.Path #10661
Closed
@hauntsaninja
hauntsaninja marked this pull request as ready for review September 4, 2023 23:58
AlexWaygood
AlexWaygood reviewed Sep 5, 2023
View reviewed changes
Comment thread test_cases/stdlib/check_pathlib.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test_cases/stdlib/check_pathlib.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@hauntsaninja @AlexWaygood
Apply suggestions from code review
c94c946
Co-authored-by: Alex Waygood <[email protected]>
AlexWaygood
AlexWaygood approved these changes Sep 5, 2023
View reviewed changes

@AlexWaygood AlexWaygood left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It still feels like we're sorta working around shortcomings in the heuristics mypy/pyright use here. (As you said in the issue, this kind of thing is going to affect anybody who writes a __eq__ method in a py.typed runtime library, and __eq__ methods are pretty common!)

But I agree that this is a pretty useful error for mypy/pyright to emit, so I'm happy for this change to be made on the basis that practicality beats purity :-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions

This comment has been minimized.

Sign in to view
@hauntsaninja

hauntsaninja commented Sep 5, 2023

Copy link
Copy Markdown
Collaborator Author

Sounds good, I'll leave open for a bit in case anyone else chimes in!

AlexWaygood and NMertsch reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Akuli
Akuli approved these changes Sep 5, 2023
View reviewed changes
@AlexWaygood

AlexWaygood commented Sep 5, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Here is a small regression that this PR causes, FYI: currently mypy will not complain about this code (on my Windows machine, the expression evaluates to True):

from pathlib import *
PureWindowsPath("foo/bar") == Path("foo/bar")

But with this PR, it will:

$ mypy -c "from pathlib import *; PureWindowsPath('foo/bar') == Path('foo/bar')" --strict-equality --custom-typeshed-dir .
<string>:1: error: Non-overlapping equality check (left operand type: "PureWindowsPath", right operand type: "Path")  [comparison-overlap]
Found 1 error in 1 file (checked 1 source file)

Is the regression that important? Probably not particularly; I don't know how many people are doing this kind of comparison. But, worth noting, I think.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hauntsaninja

hauntsaninja commented Sep 5, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator Author

@AlexWaygood oh, interesting example! Definitely a false positive in terms of what the type checker thinks it's doing, but that code is pretty suspect and I'm okay with it triggering a warning of some kind — depending on your platform, it could be true that those could never be equal!

So I think I'm still fine with the PR (though I'll certainly add test case and comments). We should experiment with making Path.__new__ more accurate in a follow up. I'm trying to teach mypy about more kinds of __new__ over here: python/mypy#16020

AlexWaygood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hauntsaninja
alex example
c97353c
@github-actions

github-actions Bot commented Sep 5, 2023

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

mkosi (https://github.com/systemd/mkosi)
+ mkosi/kmod.py:32:16: error: Non-overlapping container check (element type: "str", container item type: "Path")  [comparison-overlap]
+ mkosi/config.py:2012:8: error: Non-overlapping equality check (left operand type: "Optional[Path]", right operand type: "Literal['']")  [comparison-overlap]
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hauntsaninja hauntsaninja mentioned this pull request Sep 6, 2023
Believe more __new__ return types python/mypy#16020
Closed
@hauntsaninja
hauntsaninja merged commit 4df9634 into python:main Sep 7, 2023
@hauntsaninja
hauntsaninja deleted the pathlib-strict-eq branch September 7, 2023 07:40
@AlexWaygood

AlexWaygood commented Sep 15, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This change caught a real bug in stubtest (that was introduced by, er, me)! https://github.com/python/mypy/actions/runs/6202155467/job/16840319289?pr=16121

The first CI run on python/mypy#16121

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood AlexWaygood mentioned this pull request Sep 15, 2023
Sync typeshed python/mypy#16121
Merged
@AlexWaygood AlexWaygood mentioned this pull request Oct 6, 2023
strict equality check fails to detect non-overlap of str and Path python/mypy#16231
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Akuli Akuli Akuli approved these changes
@AlexWaygood AlexWaygood AlexWaygood approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

comparison-overlap not triggered for pathlib.Path

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@hauntsaninja @AlexWaygood @Akuli
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.