Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bpo-43012: removepathlib._Accessor#25701

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

barneygale
Copy link
Contributor

@barneygalebarneygale commentedApr 28, 2021
edited by miss-islington
Loading

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 toPath objects themselves (inc. subclasses)
  • Non-public, i.e. underscore prefixed - '_Accessor' and '_NormalAccessor'
  • Unofficially used to implement customizedPath objects, but once oncebpo-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

@barneygale
Copy link
ContributorAuthor

Note that alot of my previous pathlib bugfixes were partly in preparation for making this diff look OK! I was hoping to highlight thatPath 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 thetest_glob_permissions test wasn't working properly. I had to add akey= argument tosorted() to make things play nice, which makes me think its patching ofos.scandir() wasn't visible to pathlib previously.

@kfollstad
Copy link
Contributor

kfollstad commentedApr 29, 2021
edited
Loading

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 looppython3.10-with-accessor -m timeit -r 5 -n 100000 -s 'from pathlib import Path' 'Path.cwd()'100000 loops, best of 5: 206 usec per loopresolve()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 looppython3.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 loopopen()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 looppython3.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 looptouch()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 looppython3.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!

@barneygale
Copy link
ContributorAuthor

Yep! And you'll note that theos functions in the resulting code are called fromonly onePath method. That's to facilitate us adding a newAbstractPath class that sits betweenPurePath andPath. Certain methods likestat() would be abstract, whereas derived methods likeexists() would not.

@barneygale
Copy link
ContributorAuthor

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.

@barneygale
Copy link
ContributorAuthor

barneygale commentedMay 13, 2021
edited by bedevere-bot
Loading

@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 inbpo-26032, do you have any feedback on thePath.scandir() addition? Would you preferPath._scandir() for example? Thank you.

@serhiy-storchaka
Copy link
Member

As forPath.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 callingos.scandir()).

barneygale reacted with thumbs up emoji

@barneygalebarneygaleforce-pushed thebpo-43012-remove-pathlib-accessor branch from0124153 to599e253CompareMay 13, 2021 22:07
@barneygale
Copy link
ContributorAuthor

As forPath.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 callingos.scandir()).

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

@barneygale
Copy link
ContributorAuthor

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

@barneygalebarneygaleforce-pushed thebpo-43012-remove-pathlib-accessor branch fromb0dcbd2 to7a0882bCompareJune 12, 2021 15:27
@barneygale
Copy link
ContributorAuthor

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

@github-actions
Copy link

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

barneygale reacted with eyes emoji

@github-actionsgithub-actionsbot added the staleStale PR or inactive for long period of time. labelJul 13, 2021
@barneygalebarneygaleforce-pushed thebpo-43012-remove-pathlib-accessor branch from7a0882b tod07f465CompareJanuary 1, 2022 01:24
@barneygale
Copy link
ContributorAuthor

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

@barneygalebarneygaleforce-pushed thebpo-43012-remove-pathlib-accessor branch fromb55c5e7 to013ddc6CompareJanuary 5, 2022 02:25
@merwok
Copy link
Member

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

barneygale reacted with thumbs up emoji

@merwok
Copy link
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.

@barneygale
Copy link
ContributorAuthor

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!

These aren't necessary, and may slow things down.
Copy link
Member

@encukouencukou left a 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?

barneygale reacted with heart emoji
@barneygale
Copy link
ContributorAuthor

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!

@barneygalebarneygalemannequin mentioned this pull requestMay 28, 2022
@projetmbcprojetmbcmannequin mentioned this pull requestJun 21, 2022
jstvz added a commit to SFDO-Tooling/CumulusCI that referenced this pull requestDec 1, 2022
Python 3.11 removed pathlib._Accessor inpython/cpython#25701. Thisbroke 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 0or 1 arguments.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@miguendesmiguendesmiguendes left review comments

@encukouencukouencukou approved these changes

@merwokmerwokmerwok approved these changes

@serhiy-storchakaserhiy-storchakaAwaiting requested review from serhiy-storchaka

@pitroupitrouAwaiting requested review from pitrou

Assignees
No one assigned
Labels
staleStale PR or inactive for long period of time.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

9 participants
@barneygale@kfollstad@serhiy-storchaka@merwok@encukou@miguendes@the-knights-who-say-ni@bedevere-bot@miss-islington

[8]ページ先頭

©2009-2025 Movatter.jp