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 — bpo-43012: remove `pathlib._Accessor` by barneygale · Pull Request #25701 · python/cpython

Conversation

@barneygale

@barneygale barneygale commented Apr 28, 2021 •
edited by miss-islington
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Per Pitrou:

The original intent for the “accessor” thing was to have a variant that did all accesses under a filesystem tree in a race condition-free way using openat and friends. It turned out to be much too hairy to actually implement, so was entirely abandoned, but the accessor abstraction was left there.

https://discuss.python.org/t/make-pathlib-extensible/3428/2

Accessors are:

  • Lacking any internal purpose - '_NormalAccessor' is the only implementation
  • Lacking any firm conceptual difference to Path objects themselves (inc. subclasses)
  • Non-public, i.e. underscore prefixed - '_Accessor' and '_NormalAccessor'
  • Unofficially used to implement customized Path objects, but once once bpo-24132 is addressed there will be a supported route for that.

This patch preserves all existing behaviour.

https://bugs.python.org/issue43012

Automerge-Triggered-By: GH:encukou

Sorry, something went wrong.

Uh oh!

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

All reactions
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Apr 28, 2021
@bedevere-bot bedevere-bot added the awaiting review label Apr 28, 2021
@barneygale
barneygale force-pushed the bpo-43012-remove-pathlib-accessor branch from 3941ea1 to 5136c12 Compare April 28, 2021 23:06
@barneygale

barneygale commented Apr 28, 2021

Copy link
Copy Markdown
Contributor Author

Note that a lot of my previous pathlib bugfixes were partly in preparation for making this diff look OK! I was hoping to highlight that Path and _Accessor are conceptually the same at present, and therefore shouldn't be split across two classes. I hope this diff makes that clear! Browsing by commit might be useful also.

I'm pretty sure the test_glob_permissions test wasn't working properly. I had to add a key= argument to sorted() to make things play nice, which makes me think its patching of os.scandir() wasn't visible to pathlib previously.

All reactions

Sorry, something went wrong.

Uh oh!

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

@kfollstad

kfollstad commented Apr 29, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Bravo! I didn't realize yesterday with #25699 that it was temp code. I had seen your commits and misunderstood. I thought somehow your intent was to add a class in between Path and PurePath which leveraged moving all cwd, resolve, open, touch, into the accessor.

I had done some performance testing that move of cwd, resolve, open, touch into the accessor and noted that it resulted in a significant slow down doing so.

cwd()
python3.9 -m timeit -r 5 -n 100000 -s 'from pathlib import Path' 'Path.cwd()'
100000 loops, best of 5: 4.03 usec per loop
python3.10-with-accessor -m timeit -r 5 -n 100000 -s 'from pathlib import Path' 'Path.cwd()'
100000 loops, best of 5: 206 usec per loop

resolve()
python3.9 -m timeit -r 5 -n 50000 -s 'from pathlib import PosixPath' -s 'p = PosixPath("/usr/bin/python")' 'p.resolve()'
50000 loops, best of 5: 15.4 usec per loop
python3.10-with-accessor -m timeit -r 5 -n 50000 -s 'from pathlib import PosixPath' -s 'p = PosixPath("/usr/bin/python")' 'p.resolve()'
50000 loops, best of 5: 429 usec per loop

open()
python3.9 -m timeit -r 5 -n 100000 -s 'from pathlib import PosixPath' -s 'p = PosixPath("/var/tmp/tmpfile.txt")' 'with open(p, "w"): pass'
100000 loops, best of 5: 14 usec per loop
python3.10-with-accessor -m timeit -r 5 -n 100000 -s 'from pathlib import PosixPath' -s 'p = PosixPath("/var/tmp/tmpfile.txt")' 'with open(p, "w"): pass'
100000 loops, best of 5: 163 usec per loop

touch()
python3.9 -m timeit -r 5 -n 100000 -s 'from pathlib import PosixPath' -s 'p = PosixPath("/var/tmp/tmpfile.txt")' 'p.touch()'
100000 loops, best of 5: 1.89 usec per loop
python3.10-with-accessor -m timeit -r 5 -n 100000 -s 'from pathlib import PosixPath' -s 'p = PosixPath("/var/tmp/tmpfile.txt")' 'p.touch()'
100000 loops, best of 5: 26.1 usec per loop

I have to imagine that moving everything out will do the exact opposite and make all of these slow down go away and speed up all of the other functions that had used the accessor. That said, I'm just a guy out there who happens to be using pathlib, but I think this is brilliant.

Myself, I had been wondering about changing the name of accessor to common (or something similar) having also seen Pitrou's comment to you, since it seemed like a vestigial abstraction. But I like taking it out entirely even better. Remove the cruft and make it faster - this seems like a win!

All reactions

Sorry, something went wrong.

Uh oh!

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

@barneygale

barneygale commented Apr 29, 2021

Copy link
Copy Markdown
Contributor Author

Yep! And you'll note that the os functions in the resulting code are called from only one Path method. That's to facilitate us adding a new AbstractPath class that sits between PurePath and Path. Certain methods like stat() would be abstract, whereas derived methods like exists() would not.

All reactions

Sorry, something went wrong.

Uh oh!

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

@barneygale

barneygale commented Apr 29, 2021

Copy link
Copy Markdown
Contributor Author

I'm also planning to perform an optimization pass, as I think there's a few _from_parts() tricks missed here and there that might have slowed things down slightly. Overall I'm expecting the changes to be performance-neutral.

All reactions

Sorry, something went wrong.

Uh oh!

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

@barneygale

barneygale commented May 13, 2021 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

@pitrou I think you wrote this code originally - do you have the time/inclination to review? Thanks so much!

@serhiy-storchaka As you improved the performance of globbing in bpo-26032, do you have any feedback on the Path.scandir() addition? Would you prefer Path._scandir() for example? Thank you.

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka

serhiy-storchaka commented May 13, 2021

Copy link
Copy Markdown
Member

As for Path.scandir(), if you do not want to extend an API, do not add a public method. And if you want to add a new public method, it is a different issue which should be discussed separately (in particularly it should be shown an advantage over calling os.scandir()).

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

@barneygale
barneygale force-pushed the bpo-43012-remove-pathlib-accessor branch from 0124153 to 599e253 Compare May 13, 2021 22:07
@barneygale

barneygale commented May 13, 2021

Copy link
Copy Markdown
Contributor Author

As for Path.scandir(), if you do not want to extend an API, do not add a public method. And if you want to add a new public method, it is a different issue which should be discussed separately (in particularly it should be shown an advantage over calling os.scandir()).

Thanks very much. I've renamed it to _scandir() as it can stay private for now.

All reactions

Sorry, something went wrong.

Uh oh!

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

serhiy-storchaka
serhiy-storchaka reviewed May 14, 2021
View reviewed changes
Comment thread Lib/pathlib.py Resolved

Uh oh!

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

miguendes
miguendes reviewed May 14, 2021
View reviewed changes
Comment thread Lib/pathlib.py Resolved

Uh oh!

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

@barneygale barneygale mentioned this pull request May 15, 2021
bpo-44136: remove pathlib._Flavour #26141
Closed
@barneygale

barneygale commented May 16, 2021

Copy link
Copy Markdown
Contributor Author

I'll wait for #26153 to land before rebasing.

All reactions

Sorry, something went wrong.

Uh oh!

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

@barneygale
barneygale force-pushed the bpo-43012-remove-pathlib-accessor branch from b0dcbd2 to 7a0882b Compare June 12, 2021 15:27
@barneygale

barneygale commented Jun 12, 2021

Copy link
Copy Markdown
Contributor Author

I've rebased this PR. I believe it's ready for core review!

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions

github-actions Bot commented Jul 13, 2021

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

barneygale reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Jul 13, 2021
barneygale added 8 commits January 1, 2022 01:22
@barneygale
Call accessor.getcwd() from only one method.
7d33921
@barneygale
Call accessor.stat() from only one method.
740953b
@barneygale
Call accessor.scandir() from only one method.
57f40f7
@barneygale
Call accessor.link() from only one method.
f3855f8
@barneygale
Delete pathlib._Accessor.
734940f
@barneygale
Fix broken test_glob_permissions test.
3dfefdf
@barneygale
Rename Path.scandir() to Path._scandir()
613a171
@barneygale
Simplify handling of missing os.readlink(), symlink() and link().
d07f465
@barneygale
barneygale force-pushed the bpo-43012-remove-pathlib-accessor branch from 7a0882b to d07f465 Compare January 1, 2022 01:24
@barneygale
barneygale requested a review from serhiy-storchaka January 1, 2022 01:28
@barneygale

barneygale commented Jan 1, 2022

Copy link
Copy Markdown
Contributor Author

I'm still keen to land this if possible. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

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

@barneygale
barneygale force-pushed the bpo-43012-remove-pathlib-accessor branch from b55c5e7 to 013ddc6 Compare January 5, 2022 02:25
@merwok

merwok commented Jan 5, 2022

Copy link
Copy Markdown
Member

Please avoid force push for future PRs, they make reviewing less pleasant: https://devguide.python.org/pullrequest/

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

@barneygale
Move comment to Path._scandir() definition.
c9ffcf9
@merwok

merwok commented Jan 5, 2022

Copy link
Copy Markdown
Member

Can you add a news entry? Can be just one line or two about removing an obsolete layer and preparing the terrain for upcoming enhancements.

All reactions

Sorry, something went wrong.

Uh oh!

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

@barneygale
Add news entry
3783a6a
@barneygale

barneygale commented Jan 5, 2022

Copy link
Copy Markdown
Contributor Author

Can you add a news entry? Can be just one line or two about removing an obsolete layer and preparing the terrain for upcoming enhancements.

I've added a news entry now. I used your wording as it seemed spot on to me!

All reactions

Sorry, something went wrong.

Uh oh!

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

@barneygale
Undo changes to selector classes.
8aabc5d
These aren't necessary, and may slow things down.
@barneygale
barneygale requested a review from merwok January 16, 2022 23:07
@barneygale
Merge branch 'main' into bpo-43012-remove-pathlib-accessor
d3c363b
encukou
encukou approved these changes Jan 26, 2022
View reviewed changes

@encukou encukou left a comment

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.

To me this looks ready to merge. Is anyone else reviewing it?

Sorry, something went wrong.

Uh oh!

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

barneygale reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Jan 26, 2022
barneygale added 2 commits January 29, 2022 00:18
@barneygale
Merge branch 'main' into bpo-43012-remove-pathlib-accessor
37d5127
@barneygale
Fix up broken merge from main.
cfaf15f
merwok
merwok approved these changes Jan 29, 2022
View reviewed changes
@encukou encukou added the 🤖 automerge label Feb 2, 2022
@miss-islington
miss-islington merged commit 08f8301 into python:main Feb 2, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Feb 2, 2022
@barneygale

barneygale commented Feb 2, 2022

Copy link
Copy Markdown
Contributor Author

Thank you for the reviews, everyone. If you can spare the time to continue reviewing this PR series, the next one is at #31085. Thanks so much!

All reactions

Sorry, something went wrong.

Uh oh!

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

@barneygale barneygale mannequin mentioned this pull request May 28, 2022
Remove pathlib accessors #87178
Closed
@projetmbc projetmbc mannequin mentioned this pull request Jun 21, 2022
Direct sub-classing of pathlib.Path #68320
Closed
This was referenced Sep 6, 2022
python3.11 - AttributeError: module 'pathlib' has no attribute '_Accessor' devopshq/artifactory#372
Closed
support python 3.11 devopshq/artifactory#376
Merged
@wookayin wookayin mentioned this pull request Nov 10, 2022
Add python 3.11 support: Remove use of pathlib._Accessor justindujardin/pathy#88
Closed
@donhui donhui mentioned this pull request Nov 29, 2022
glob method broken in python 3.11 devopshq/artifactory#396
Closed
jstvz added a commit to SFDO-Tooling/CumulusCI that referenced this pull request Dec 1, 2022
@jstvz
Update create_task_fixture for 3.11
7532b6a
Python 3.11 removed pathlib._Accessor in python/cpython#25701. This
broke our patch when it replaced a call to `os.getcwd()` with
`Path.cwd()` in `Path.absolute()`. As a classmethod `Path.cwd()`
receives the class as its implicit first argument meaning we can have 0
or 1 arguments.
@jstvz jstvz mentioned this pull request Dec 1, 2022
Fix unit tests on Python 3.11 SFDO-Tooling/CumulusCI#3456
Merged
@PribhuPatel PribhuPatel mentioned this pull request Jun 26, 2023
dohq-artifactory doesn't work with Python 3.11.2 devopshq/artifactory#415
Closed
@barneygale barneygale mentioned this pull request Sep 11, 2023
GH-89812: Add pathlib._PathBase #106337
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@encukou encukou encukou approved these changes
@merwok merwok merwok approved these changes
@serhiy-storchaka serhiy-storchaka Awaiting requested review from serhiy-storchaka
@pitrou pitrou Awaiting requested review from pitrou
+1 more reviewer
@miguendes miguendes miguendes left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

Labels

stale Stale PR or inactive for long period of time.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

9 participants

@barneygale @kfollstad @serhiy-storchaka @merwok @encukou @miguendes @the-knights-who-say-ni @bedevere-bot @miss-islington
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 01402503 — 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.