[issue44136] Remove pathlib flavours
Change by Barney Gale : -- pull_requests: +28536 pull_request: https://github.com/python/cpython/pull/30320 ___ Python tracker <https://bugs.python.org/issue44136> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44136] Remove pathlib flavours
Change by Barney Gale : -- pull_requests: +28537 pull_request: https://github.com/python/cpython/pull/30321 ___ Python tracker <https://bugs.python.org/issue44136> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue45649] Add tarinfo.Path
Barney Gale added the comment: It's possible to do, but will be a little slow due to the nature of tar files. They're a big linked list of files, so you need to do a bunch of reads/seeks from the start to the end to enumerate all files. I'd ask that we try to get issue24132 solved first. That would let us write: # tarfile.py class Path(pathlib.AbstractPath): def iterdir(self): ... def stat(self): ... We'd fill in a smallish number of abstract methods to get a full `Path`-compatible class with `read_text()`, `is_symlink()` etc methods. -- nosy: +barneygale ___ Python tracker <https://bugs.python.org/issue45649> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue45649] Add tarinfo.Path
Barney Gale added the comment: If you're only aiming for Traversable compatibility, sure. The original bug description asks for something that's pathlib-compatible and similar to zipfile.Path, which goes beyond the Traversable interface in attempting to emulate pathlib.Path. The pathlib.Path interface is a good one - I see no reason it can't apply to zip and tar archives in full. Methods of Path objects already raise NotImplementedError if operations aren't supported (e.g. creating symlinks) Some prototyping from a couple years back, including a tar path implementation: https://github.com/barneygale/pathlab/tree/master/pathlab -- ___ Python tracker <https://bugs.python.org/issue45649> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46227] add pathlib.Path.walk method
Change by Barney Gale : -- nosy: +barneygale ___ Python tracker <https://bugs.python.org/issue46227> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46148] Optimize pathlib
Change by Barney Gale : -- nosy: +barneygale nosy_count: 8.0 -> 9.0 pull_requests: +28697 pull_request: https://github.com/python/cpython/pull/30492 ___ Python tracker <https://bugs.python.org/issue46148> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46316] Optimize pathlib.Path.iterdir()
New submission from Barney Gale : pathlib.Path.iterdir() contains the following code: if name in {'.', '..'}: # Yielding a path object for these makes little sense continue This check is unnecessary as os.listdir() does not return entries for '.' or '..': os.listdir(path='.') Return a list containing the names of the entries in the directory given by path. The list is in arbitrary order, and does not include the special entries '.' and '..' even if they are present in the directory See https://docs.python.org/3/library/os.html#os.listdir -- components: Library (Lib) messages: 410154 nosy: barneygale priority: normal severity: normal status: open title: Optimize pathlib.Path.iterdir() versions: Python 3.11 ___ Python tracker <https://bugs.python.org/issue46316> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46316] Optimize pathlib.Path.iterdir()
Change by Barney Gale : -- keywords: +patch pull_requests: +28707 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30501 ___ Python tracker <https://bugs.python.org/issue46316> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46317] Pathlib.rename isn't robust
Barney Gale added the comment: Sounds good. Would you expose the `copy_function` argument in pathlib, or do something else (like `metadata=True`)? -- nosy: +barneygale ___ Python tracker <https://bugs.python.org/issue46317> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46317] Pathlib.rename isn't robust
Barney Gale added the comment: shutil.move() accepts a `copy_function` argument: shutil.move(src, dst, copy_function=copy2) It's possible to set `copy_function=copy` to skip copying file metadata. -- ___ Python tracker <https://bugs.python.org/issue46317> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46317] Pathlib.rename isn't robust
Barney Gale added the comment: Fair enough. Users who wanted to avoid copying file metadata would then do something like this, I suppose? import pathlib import shutil path = pathlib.Path('foo') path.move('bar', copy_function=shutil.copy) I guess the downside here is that users would still need to `import shutil` to do this. But I see the utility of allowing any copy_function to be supplied! -- ___ Python tracker <https://bugs.python.org/issue46317> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue43012] Remove pathlib accessors
Barney Gale added the comment: Thank you Éric! -- ___ Python tracker <https://bugs.python.org/issue43012> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue34526] Path.relative_to() taking multiple arguments could be better documented
Change by Barney Gale : -- nosy: +barneygale ___ Python tracker <https://bugs.python.org/issue34526> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46554] Add append keyword argument to Path.write_text() and Path.write_bytes()
Barney Gale added the comment: >From https://stackoverflow.com/a/68969892 > I think a major reason why pathlib.Path objects don't (and, indeed, > shouldn't) have a append_text method is because it creates a hole for > inexperienced users to fall into, which is a huge sin in API design. > Specifically, the hole I'm referring to is using append_text on the > same file repeatedly in a loop. Because you're continually opening > and closing the file, it is slow. Plus, doing so many unnecessary > writes is probably not great for the health of your hard drive. > Worse, because the program will actually behave correctly (e.g. the > file will have the contents they intended), they may not even notice > anything is wrong, because they don't necessarily have a mental gauge > on how long writing to a file "should" take. Most of the time you don't need an 'append' mode. And when you do, most of the time you'll need to append multiple times, in which case `path.open('a')` is a much better bet. -- nosy: +barneygale ___ Python tracker <https://bugs.python.org/issue46554> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46556] pathlib.Path.__enter__() should emit DeprecationWarning
New submission from Barney Gale : In Python 3.9 / issue39682 we made Path.__exit__() a no-op, and added a comment in the code mentioning that it should be deprecated in future. The future is here, so let's deprecate it. -- components: Library (Lib) messages: 411936 nosy: barneygale priority: normal severity: normal status: open title: pathlib.Path.__enter__() should emit DeprecationWarning type: behavior versions: Python 3.11 ___ Python tracker <https://bugs.python.org/issue46556> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39682] pathlib.Path objects can be used as context managers
Change by Barney Gale : -- pull_requests: +29150 pull_request: https://github.com/python/cpython/pull/30971 ___ Python tracker <https://bugs.python.org/issue39682> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46556] pathlib.Path.__enter__() should emit DeprecationWarning
Change by Barney Gale : -- keywords: +patch pull_requests: +29149 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30971 ___ Python tracker <https://bugs.python.org/issue46556> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29688] Add support for Path.absolute()
Barney Gale added the comment: Now that GH 26153 is merged, I think this bug can be resolved. -- ___ Python tracker <https://bugs.python.org/issue29688> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46554] Add append keyword argument to Path.write_text() and Path.write_bytes()
Barney Gale added the comment: New users who want to add lines to a file will see this method and do: for line in blah: path.write_text(line, append=True) Which repeatedly opens/closes the file. This is a foot-shotgun; it shouldn't be added to pathlib IMO. -- ___ Python tracker <https://bugs.python.org/issue46554> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29688] Add support for Path.absolute()
Barney Gale added the comment: @eryksun thanks for flagging, a couple thoughts: I'd imagine that bug is reproducible with `Path('C:\\Temp', 'C:')` already, right? If that's the case, should it logged as a separate issue? I'm planning to /experimentally/ throw away pathlib's internal path parsing logic and defer to `posixpath` / `ntpath` instead. I suspect this bug and others will be fixed by that change, but I need to see what the performance impact will be. -- ___ Python tracker <https://bugs.python.org/issue29688> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24132] Direct sub-classing of pathlib.Path
Change by Barney Gale : -- pull_requests: +29269 pull_request: https://github.com/python/cpython/pull/31085 ___ Python tracker <https://bugs.python.org/issue24132> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46654] file_open doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)
Barney Gale added the comment: Why are you adding `.as_uri()`? -- nosy: +barneygale ___ Python tracker <https://bugs.python.org/issue46654> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46654] file_open doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)
Barney Gale added the comment: urllib uses nturl2path under the hood. On my system it seems to return reasonable results for both two and four leading slashes: >>> nturl2path.url2pathname('host/share/test.py') 'host\\share\\test.py' >>> nturl2path.url2pathname('//host/share/test.py') 'host\\share\\test.py' (note that urllib strips the `file:` prefix before calling this function). -- ___ Python tracker <https://bugs.python.org/issue46654> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46654] urllib.request.urlopen doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)
Barney Gale added the comment: Agree with the previous analysis. Just noting that: >>> nturl2path.pathname2url('host\\share\\test.py') 'host/share/test.py' So four slashes are produced by the urllib code, whereas pathlib only produces two. According to wikipedia, both the two- and four-slash variants are in active usage. As we can see within Python itself! :P -- ___ Python tracker <https://bugs.python.org/issue46654> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46654] urllib.request.urlopen doesn't handle UNC paths produced by pathlib's as_uri() (but can handle UNC paths with additional slashes)
Change by Barney Gale : -- title: urllib.request.urlopen doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes) -> urllib.request.urlopen doesn't handle UNC paths produced by pathlib's as_uri() (but can handle UNC paths with additional slashes) ___ Python tracker <https://bugs.python.org/issue46654> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46733] pathlib.Path methods can raise NotImplementedError
New submission from Barney Gale : The docs for NotImplementedError say: > In user defined base classes, abstract methods should raise this exception > when they require derived classes to override the method, or while the class > is being developed to indicate that the real implementation still needs to be > added. pathlib's use of NotImplementedError appears to be more broad. It can be raised in the following circumstances: 1. When attempting to construct a WindowsPath from a non-Windows system, and vice-versa. This is the only case where NotImplementedError is mentioned in the pathlib docs (in a repl example) 2. In glob() and rglob() when an absolute path is supplied as a pattern 3. In owner() if the pwd module isn't available 4. In group() if the grp module isn't available 5. In readlink() if os.readlink() isn't available 6. In symlink_to() if os.symlink() isn't available 7. In hardlink_to() if os.hardlink() isn't available 8. In WindowsPath.is_mount(), unconditionally I suspect there are better choices for exception types in all these cases. -- components: Library (Lib) messages: 413142 nosy: barneygale priority: normal severity: normal status: open title: pathlib.Path methods can raise NotImplementedError type: behavior versions: Python 3.11 ___ Python tracker <https://bugs.python.org/issue46733> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46733] pathlib.Path methods can raise NotImplementedError
Change by Barney Gale : -- keywords: +patch pull_requests: +29461 stage: -> patch review pull_request: https://github.com/python/cpython/pull/31085 ___ Python tracker <https://bugs.python.org/issue46733> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46733] pathlib.Path methods can raise NotImplementedError
Change by Barney Gale : -- keywords: +patch pull_requests: +29489 stage: -> patch review pull_request: https://github.com/python/cpython/pull/31338 ___ Python tracker <https://bugs.python.org/issue46733> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46733] pathlib.Path methods can raise NotImplementedError
Change by Barney Gale : -- pull_requests: +29490 pull_request: https://github.com/python/cpython/pull/31339 ___ Python tracker <https://bugs.python.org/issue46733> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46733] pathlib.Path methods can raise NotImplementedError
Change by Barney Gale : -- pull_requests: +29492 pull_request: https://github.com/python/cpython/pull/31341 ___ Python tracker <https://bugs.python.org/issue46733> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46733] pathlib.Path methods can raise NotImplementedError
Change by Barney Gale : -- pull_requests: +29491 pull_request: https://github.com/python/cpython/pull/31340 ___ Python tracker <https://bugs.python.org/issue46733> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46733] pathlib.Path methods can raise NotImplementedError
Barney Gale added the comment: Thanks very much Alex. I've added some PRs: PR 31338 addresses owner(), group() and is_mount(). It moves those methods to PosixPath, and adds stubs in WindowsPath that raise deprecation warnings. I agree with your analysis that, for static typing purposes, these methods shouldn't even exist on WindowsPath! PR 31339 addresses readlink(), symlink_to() and hardlink_to(). In this case I'm working towards making those methods unavailable if os.readlink(), symlink() and link() are unavailable. Not totally sold on this - thoughts? PR 31340 addresses glob() and rglob(), switching the exception type to ValueError. I think this is a legitimate bugfix with minimal adverse effects. PR 31341 addresses the Path constructor. This is a backwards incompatible change, and /probably/ not worth doing. I add it for completeness sake, as these four PRs cover all cases where pathlib raises NotImplementedError. -- ___ Python tracker <https://bugs.python.org/issue46733> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46733] pathlib.Path methods can raise NotImplementedError
Barney Gale added the comment: I'm planning to learn more heavily on posixpath + ntpath in pathlib once bpo-44136 is done. I think that would be a good time to introduce is_mount() support on Windows. -- ___ Python tracker <https://bugs.python.org/issue46733> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42777] WindowsPath does not implement is_mount but ntpath implements and offers a ismount method
Change by Barney Gale : -- keywords: +patch nosy: +barneygale nosy_count: 1.0 -> 2.0 pull_requests: +29587 stage: -> patch review pull_request: https://github.com/python/cpython/pull/31458 ___ Python tracker <https://bugs.python.org/issue42777> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46733] pathlib.Path methods can raise NotImplementedError
Barney Gale added the comment: Thanks both. I've adjusted PR 31338 to leave is_mount() unchanged. I've opened a new pull request that implements is_mount() on Windows using ntpath.ismount(): PR 31458 -- ___ Python tracker <https://bugs.python.org/issue46733> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44136] Remove pathlib flavours
Barney Gale added the comment: ^ just to bring my previous comment up-to-date: I'm no longer pursuing adding `os.path.isreserved()` and `os.path.fileuri()` functions, or modifying `normpath()`. At least, not for now! Instead, my plan is to move flavour functionality as follows (as classmethods with underscore prefixes): _Flavour--> PurePath _PosixFlavour --> PurePath _WindowsFlavour --> PureWindowsPath As a result, PurePath will use POSIX syntax by default. This is fully backwards-compatible, as users can't create PurePath objects! PurePath.__new__() instantiates PurePosixPath or PureWindowsPath. But it will matter for future user subclasses of PurePath/Path, where we usually want POSIX syntax. I think there will be three PRs involved. PR 30320 and PR 30321 move _Flavour.make_uri() and _Flavour.is_reserved() respectively; these are reasonably standalone. If/when they land, I'll make a larger PR that moves the remaining methods into PurePath and PureWindowsPath. -- ___ Python tracker <https://bugs.python.org/issue44136> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue45991] Improve ambiguous docstrings in pkgutil
Barney Gale added the comment: Should pkgutil call os.fspath() in this case? -- nosy: +barneygale ___ Python tracker <https://bugs.python.org/issue45991> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24132] Direct sub-classing of pathlib.Path
Change by Barney Gale : -- pull_requests: +29812 pull_request: https://github.com/python/cpython/pull/31691 ___ Python tracker <https://bugs.python.org/issue24132> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44136] Remove pathlib flavours
Change by Barney Gale : -- pull_requests: +29813 pull_request: https://github.com/python/cpython/pull/31691 ___ Python tracker <https://bugs.python.org/issue44136> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37609] support "UNC" device paths in ntpath.splitdrive
Barney Gale added the comment: I'd like to pick this up, as it would allow us to remove a duplicate implementation in pathlib with its own shortcomings. If using native functionality if difficult to get right, could I put @eryksun's splitdrive.py implementation up for review? -- nosy: +barneygale ___ Python tracker <https://bugs.python.org/issue37609> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37609] support "UNC" device paths in ntpath.splitdrive
Change by Barney Gale : -- pull_requests: +29822 pull_request: https://github.com/python/cpython/pull/31702 ___ Python tracker <https://bugs.python.org/issue37609> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24132] Direct sub-classing of pathlib.Path
Barney Gale added the comment: If/when GH-31691 lands, I think this bug can be resolved: the original repro case will no longer raise AttributeError, and subclasses will be able to customize behaviour without needing to define further "flavour" or "accessor" subclasses. -- ___ Python tracker <https://bugs.python.org/issue24132> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue47161] pathlib method relative_to doesnt work with // in paths
Change by Barney Gale : -- nosy: +barneygale ___ Python tracker <https://bugs.python.org/issue47161> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39090] Document various options for getting the absolute path from pathlib.Path objects
Barney Gale added the comment: The docs for PurePath.is_absolute() say: > A path is considered absolute if it has both a root and (if the flavour > allows) a drive This does not preclude it from having ".." segments. PurePath.absolute() is documented as of bpo-29688 / 3.11, see: https://docs.python.org/3.11/library/pathlib.html#pathlib.Path.absolute The documentation for the absolute() method is deliberately placed alongside resolve() for ease of comparison. Both methods make a path absolute, but resolve() also follows symlinks, and consequently is able to safely elide ".." segments. -- ___ Python tracker <https://bugs.python.org/issue39090> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40107] pathlib: make `_Accessor.open()` return a file object and not a file descriptor
Change by Barney Gale : -- keywords: +patch pull_requests: +23978 stage: -> patch review pull_request: https://github.com/python/cpython/pull/25240 ___ Python tracker <https://bugs.python.org/issue40107> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24132] Direct sub-classing of pathlib.Path
Change by Barney Gale : -- pull_requests: +23979 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/25240 ___ Python tracker <https://bugs.python.org/issue24132> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue43757] pathlib: move 'resolve()' logic out of path flavour
New submission from Barney Gale : Under-the-hood functionality in pathlib is divided between: - The 'flavour', which implements path syntax (separators, casefolding, etc) - The 'accessor', which accesses the local (file)system. The '_WindowsFlavour/_PosixFlavour.resolve()' function is misplaced, as it requires OS calls such as `os.getcwd()`, `os.readlink()`, and `nt._getfinalpathname()`. While the implementation *does* differ across Windows and POSIX, it's still properly part of the accessor interface, and not the flavour interface. In preparation for addressing bpo-24132 I'd like to get these interfaces really tidy. Once bpo-39899 is fixed, this will be the last remaining flavour method that does accessor-y things. -- components: Library (Lib) messages: 390397 nosy: barneygale priority: normal severity: normal status: open title: pathlib: move 'resolve()' logic out of path flavour type: enhancement versions: Python 3.10 ___ Python tracker <https://bugs.python.org/issue43757> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`
Barney Gale added the comment: Thanks for taking a look, Steve. A couple things maybe worth noting: Firstly, `os.path.expanduser()` is already documented to return the path unchanged if the home directory can't be resolved: > If the expansion fails or if the path does not begin with a tilde, the path > is returned unchanged. Secondly, `ntpath.expanduser()` already returns the path unchanged if neither USERPROFILE nor HOMEPATH are in the environment. An alternative would be to leave `ntpath.expanduser()` method alone, and forgo the slightly-improved error checking in `WindowsPath.expanduser()` in the name of conformity. Or perhaps we could add a `stict` parameter to `expanduser()`? I can understand why this could be seen as change for change's sake. In fact this code removal greatly aids my work towards addressing bpo-24132. Thanks again -- resolution: -> not a bug stage: patch review -> resolved status: open -> closed versions: +Python 3.9 -Python 3.10 ___ Python tracker <https://bugs.python.org/issue39899> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`
Barney Gale added the comment: Apologies, I think I started writing a comment before your reply was posted, which undid your changes. -- resolution: not a bug -> status: closed -> open versions: +Python 3.10 -Python 3.9 ___ Python tracker <https://bugs.python.org/issue39899> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue43757] pathlib: move 'resolve()' logic out of path flavour
Change by Barney Gale : -- keywords: +patch pull_requests: +24000 stage: -> patch review pull_request: https://github.com/python/cpython/pull/25264 ___ Python tracker <https://bugs.python.org/issue43757> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27002] Support different modes in posixpath.realpath()
Barney Gale added the comment: Just stumbled upon this issue after submitting a PR: https://github.com/python/cpython/pull/25264 In my PR, `strict=False` is like `--canonicalize-missing`, and `strict=True` is like `--canonicalize-existing`. Looks like our patches are along similar lines. I've missed a trick by not calling `stat()` to trigger the ELOOP error. -- nosy: +barneygale ___ Python tracker <https://bugs.python.org/issue27002> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24132] Direct sub-classing of pathlib.Path
Change by Barney Gale : -- pull_requests: +24005 pull_request: https://github.com/python/cpython/pull/25271 ___ Python tracker <https://bugs.python.org/issue24132> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42998] pathlib.Path: add `username` argument to `home()`
Change by Barney Gale : -- keywords: +patch pull_requests: +24004 stage: -> patch review pull_request: https://github.com/python/cpython/pull/25271 ___ Python tracker <https://bugs.python.org/issue42998> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue930024] os.path.realpath can't handle symlink loops
Change by Barney Gale : -- nosy: +barneygale nosy_count: 3.0 -> 4.0 pull_requests: +24006 pull_request: https://github.com/python/cpython/pull/25264 ___ Python tracker <https://bugs.python.org/issue930024> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`
Change by Barney Gale : -- pull_requests: +24014 stage: resolved -> patch review pull_request: https://github.com/python/cpython/pull/25277 ___ Python tracker <https://bugs.python.org/issue39899> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42998] pathlib.Path: add `username` argument to `home()`
Barney Gale added the comment: Thanks for the feedback. 1. We can check the return value, like we do in `Path.expanduser()` 2. Seems like expected behaviour? 3. Worth fixing in `ntpath.expanduser()` I think. See Eryk Sun's comment here: https://bugs.python.org/issue39899#msg390507 -- ___ Python tracker <https://bugs.python.org/issue42998> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`
Barney Gale added the comment: Good spot Eryk - I've put in another PR to address it. -- ___ Python tracker <https://bugs.python.org/issue39899> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue43936] os.path.realpath() normalizes paths before resolving links on Windows
New submission from Barney Gale : Capturing a write-up by eryksun on GitHub into a new bug. Link: https://github.com/python/cpython/pull/25264#pullrequestreview-631787754 > `nt._getfinalpathname()` opens a handle to a file/directory with > `CreateFileW()` and calls `GetFinalPathNameByHandleW()`. The latter makes a > few system calls to get the final opened path in the filesystem (e.g. > "\Windows\explorer.exe") and the canonical DOS name of the volume device on > which the filesystem is mounted (e.g. "\Device\HarddiskVolume2" -> "\\?\C:") > in order to return a canonical DOS path (e.g. "\\?\C:\Windows\explorer.exe"). > > Opening a handle with `CreateFileW()` entails first getting a fully-qualified > and normalized NT path, which, among other things, entails resolving ".." > components naively in the path string. This does not take reparse points such > as symlinks and mountpoints into account. The only time Windows parses ".." > components in an opened path the way POSIX does is in the kernel when they're > in the target path of a relative symlink. > > `nt.readlink()` opens a handle to the file with the flag > `FILE_FLAG_OPEN_REPARSE_POINT`. If the final path component is a reparse > point, it opens it instead of traversing it. Then the reparse point is read > with the filesystem control request, `FSCTL_GET_REPARSE_POINT`. System > symlinks and mountpoints (`IO_REPARSE_TAG_SYMLINK` and > `IO_REPARSE_TAG_MOUNT_POINT`) are the only supported name-surrogate > reparse-point types, though `os.stat()` and `os.lstat()` handle all > name-surrogate types as 'links'. Moreover, only symlinks get the `S_IFLNK` > mode flag in a stat result, because they're the only ones we can create with > `os.symlink()` to satisfy the usage `if os.path.islink(src): > os.symlink(os.readlink(src), dst)`. > > > What would it take to do a POSIX-style "normalize as we resolve", > > and would we want to? I guess we'd need to call nt._getfinalpathname() > > on each path component in turn (C:, C:\Users, C:\Users\Barney etc), > > which from my pretty basic Windows knowledge might be rather slow if > > that involves file handles. > > You asked, so I decided to write up an outline of what implementing a > POSIX-style `realpath()` might look like in Windows. At its core, it's > similar to POSIX: lstat(), and, for a symlink, readlink() and recur. The > equivalent calls in Windows are the following: > > * `CreateFileW()` (open a handle) > > * `GetFileInformationByHandleEx()`: `FileAttributeTagInfo` > > * `DeviceIoControl()`: `FSCTL_GET_REPARSE_POINT` > > > A symlink has the reparse tag `IO_REPARSE_TAG_SYMLINK`. > > Filesystem mountpoints (aka junctions, which are like Unix bind mountpoints) > must be retained in the resolved path in order to correctly resolve relative > symlinks such as "\spam" (relative to the resolved device) and "..\..\spam". > Anyway, this is consistent with the UNC case, since mountpoints on a remote > server can never be resolved (i.e. a final UNC path never resolves > mountpoints). > > Here are some of the notable differences compared to POSIX: > > * If the source path is not a "\\?\" verbatim path, `GetFullPathNameW()` > must be called initially. However, ".." components in the target path of a > relative symlink must be resolved the POSIX way, else symlinks in the target > path may be removed incorrectly before their target is resolved (e.g. > "foo\symlink\..\bar" incorrectly resolved as "foo\bar"). The opened path is > initially normalized as follows: > > * replace forward slashes with backslashes > * collapse repeated backslashes (except the UNC root must have exactly > two backslashes) > * resolve a relative path (e.g. "spam"), drive-relative path (e.g. > "Z:spam"), or rooted path (e.g. "\spam") as a fully-qualified path (e.g. > "Z:\eggs\spam") > * resolve "." and ".." components in the opened path (naive to symlinks) > * strip trailing spaces and dots from the final component (e.g. > "C:\spam. . ." -> "C:\spam") > * resolve reserved device names in the final component of a non-UNC > path (e.g. "C:\nul" -> "\\.\nul") > > * Substitute drives (e.g. created by "subst.exe", or `DefineDosDeviceW`) > and mapped drives (e.g. created by "net.exe", or `WNetAddConnection2W`) must > be resolved, respectively via `QueryDosDeviceW()` and > `WNetGetUniversalNameW()`. Like all DOS
[issue42998] pathlib.Path: add `username` argument to `home()`
Barney Gale added the comment: Thanks very much for taking a look. I can understand the view that, given the unreliability of `os.path.expanduser('~foo')`, we shouldn't be making that functionality *more* available. My argument for this being a reasonable change is as follows: Firstly, `os.getcwd()` is a more fundamental operation than `os.path.absolute()`. In both pathlib and os.path, the `absolute()` implementation is built on the `getcwd()` implementation. The process is: call the more fundamental operation, and append whatever else was passed as an argument. Analagously, `gethomedir()` is a more fundamental operation than `expanduser()`. In the same way, `expanduser()` can call a more fundamental operation and then append the path passed in. Secondly, for a `pathlib.AbstractPath` implementation, it's a much cleaner API to have `getcwd()` and `gethomedir()` as abstract methods with identical signatures, and `absolute()` and `expanduser()` with default implementations. Thirdly, if there's are issues with the implementation for retrieving other user's home directories, those should be treated as individual issues with their own bugs, and we should add suitable warnings in the docs in the short term. My patch should make these cases *easier* to solve as we no longer have two competing implementations of the same thing. Finally, I don't think anyone is going to see `home('barney')` in the docs and decided to retrieve a user's home directory on a whim. If someone *does* need to retrieve another user's home directory, they're going to use `Path('~' + user).expanduser()` if `Path.home(user)` isn't available. My argument mostly comes from the similarities I perceive between getcwd/absolute and gethomedir/expanduser. We don't expect users to `os.path.absolute('.')` to get the current working directory, after all! But perhaps I've overestimated the similarities here. Any thoughts? Thanks again for taking a look. -- ___ Python tracker <https://bugs.python.org/issue42998> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42998] pathlib.Path: add `username` argument to `home()`
Barney Gale added the comment: In the previous comment, I was referring to bpo-39899 when I referred to "my patch". Long day! :D -- ___ Python tracker <https://bugs.python.org/issue42998> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42998] pathlib.Path: add `username` argument to `home()`
Barney Gale added the comment: Totally valid! I suppose it hinges on the relatively likelihood/unlikelihood of us being able to make `expanduser('~foo')` reliable in future. On this question I'm relieved to defer to the experts! @eryksun: penny for your thoughts? -- ___ Python tracker <https://bugs.python.org/issue42998> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42998] pathlib.Path: add `username` argument to `home()`
Barney Gale added the comment: So far I've been keen to keep the Path and AbstractPath APIs the same, but perhaps this case warrants an exception. What if AbstractPath lacked both home() and expanduser(), and those methods only existed on Path? Of all the methods on Path, these two are the *least* useful for non-local filesystems. We can then circle back round to this issue when the fate of expanduser() becomes clearer. Does that sound any good? -- ___ Python tracker <https://bugs.python.org/issue42998> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24132] Direct sub-classing of pathlib.Path
Change by Barney Gale : -- pull_requests: +24392 pull_request: https://github.com/python/cpython/pull/25701 ___ Python tracker <https://bugs.python.org/issue24132> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue43012] Remove pathlib accessors
Change by Barney Gale : -- keywords: +patch pull_requests: +24391 stage: -> patch review pull_request: https://github.com/python/cpython/pull/25701 ___ Python tracker <https://bugs.python.org/issue43012> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24132] Direct sub-classing of pathlib.Path
Barney Gale added the comment: Progress report: I've been working on tidying up the pathlib internals over the 3.9 and 3.10 releases. We're now in a position where: - `pathlib._Flavour` is entirely pure, and doesn't make any `os` calls - `pathlib._Accessor` handles all `os` access. The internal abstractions are now much tighter, which allows us to begin refactoring them with confidence! The next step is to remove accessors, in bpo-43012. After that I'll finally be in a position to start working on this bug! -- ___ Python tracker <https://bugs.python.org/issue24132> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39906] pathlib.Path: add `follow_symlinks` argument to `stat()` and `chmod()`
Change by Barney Gale : -- pull_requests: +24726 pull_request: https://github.com/python/cpython/pull/26087 ___ Python tracker <https://bugs.python.org/issue39906> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue43757] pathlib: move 'resolve()' logic out of path flavour
Change by Barney Gale : -- pull_requests: +24727 pull_request: https://github.com/python/cpython/pull/26088 ___ Python tracker <https://bugs.python.org/issue43757> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39906] pathlib.Path: add `follow_symlinks` argument to `stat()` and `chmod()`
Change by Barney Gale : -- pull_requests: +24728 pull_request: https://github.com/python/cpython/pull/26089 ___ Python tracker <https://bugs.python.org/issue39906> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue43757] pathlib: move 'resolve()' logic out of path flavour
Change by Barney Gale : -- pull_requests: +24729 pull_request: https://github.com/python/cpython/pull/26090 ___ Python tracker <https://bugs.python.org/issue43757> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue26032] Use scandir() to speed up pathlib globbing
Change by Barney Gale : -- nosy: +barneygale nosy_count: 8.0 -> 9.0 pull_requests: +24730 pull_request: https://github.com/python/cpython/pull/25701 ___ Python tracker <https://bugs.python.org/issue26032> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44119] Use glob.glob() to implement pathlib.Path.glob()
New submission from Barney Gale : I have a scratchy patch that replaces pathlib's globbing implementation with glob.glob(), which gained a `root_dir` argument in bpo-38144 Encouraging timings: $ ./python -m timeit -s "from pathlib import Path; p = Path()" -- "list(p.glob('**/*'))" Unpatched: 43.2 msec per loop Patched: 4.37 msec per loop $ ./python -m timeit -s "from pathlib import Path; p = Path('/usr/')" -- "list(p.glob('lib*/**/*'))" Unpatched: 248 msec per loop Patched: 56.8 msec per loop $ ./python -m timeit -s "from pathlib import Path; p = Path('/usr/')" -- "list(p.glob('lib*/**/'))" Unpatched: 78.3 msec per loop Patched: 2.23 msec per loop Patch to follow. -- components: Library (Lib) messages: 393556 nosy: barneygale priority: normal severity: normal status: open title: Use glob.glob() to implement pathlib.Path.glob() type: performance versions: Python 3.11 ___ Python tracker <https://bugs.python.org/issue44119> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44119] Use glob.glob() to implement pathlib.Path.glob()
Barney Gale added the comment: Flawed implementation, timings were bogus. Closing in shame. -- resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python tracker <https://bugs.python.org/issue44119> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue43012] Remove pathlib accessors
Change by Barney Gale : -- type: -> performance versions: +Python 3.11 ___ Python tracker <https://bugs.python.org/issue43012> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44136] Remove pathlib flavours
New submission from Barney Gale : Following bpo-39899, bpo-43757 and bpo-43012, `pathlib._Flavour` and its subclasses are looking a bit pointless. The implementations of `is_reserved()` and `make_uri()` (~`as_uri()`) can be readily moved to into `PurePosixPath` and `PureWindowsPath`, which removes some indirection. This follows the pattern of OS-specific stuff in `PosixPath` and `WindowsPath`. The remaining methods, such as `splitroot()`, can be pulled into `Pure*Path` with an underscore prefix. I'm generally a believer in composition over inheritance, but in this case `_Flavour` seems too small and too similar to `PurePath` to separate out into 3 extra classes. There should be no impact on public APIs or performance. -- components: Library (Lib) messages: 393685 nosy: barneygale priority: normal severity: normal status: open title: Remove pathlib flavours type: behavior versions: Python 3.11 ___ Python tracker <https://bugs.python.org/issue44136> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44136] Remove pathlib flavours
Change by Barney Gale : -- keywords: +patch pull_requests: +24776 stage: -> patch review pull_request: https://github.com/python/cpython/pull/26141 ___ Python tracker <https://bugs.python.org/issue44136> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24132] Direct sub-classing of pathlib.Path
Change by Barney Gale : -- pull_requests: +24778 pull_request: https://github.com/python/cpython/pull/26141 ___ Python tracker <https://bugs.python.org/issue24132> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29688] Add support for Path.absolute()
Change by Barney Gale : -- keywords: +patch nosy: +barneygale nosy_count: 8.0 -> 9.0 pull_requests: +24787 stage: -> patch review pull_request: https://github.com/python/cpython/pull/26153 ___ Python tracker <https://bugs.python.org/issue29688> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29688] Add support for Path.absolute()
Barney Gale added the comment: New PR up here: https://github.com/python/cpython/pull/26153 The correspondence between `pathlib` and `os.path` is as follows: - `Path.resolve()` is roughly `os.path.realpath()` - `Path.absolute()` is roughly `os.path.abspath()` Differences: - `resolve()` always raises RuntimeError on symlink loops, whereas `realpath()` either raises OSError or nothing depending on *strict*. - `absolute()` doesn't normalize the path, whereas `abspath()` does. Normalizing without resolving symlinks can change the meaning of the path, so pathlib does the better thing here. -- ___ Python tracker <https://bugs.python.org/issue29688> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39950] Add pathlib.Path.hardlink_to()
Change by Barney Gale : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python.org/issue39950> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39924] pathlib handles missing `os.link`, `os.symlink` and `os.readlink` inconsistently
Change by Barney Gale : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python.org/issue39924> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39950] Add pathlib.Path.hardlink_to()
Change by Barney Gale : -- resolution: fixed -> status: closed -> open ___ Python tracker <https://bugs.python.org/issue39950> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39950] Add pathlib.Path.hardlink_to()
Change by Barney Gale : -- pull_requests: +24789 stage: resolved -> patch review pull_request: https://github.com/python/cpython/pull/26155 ___ Python tracker <https://bugs.python.org/issue39950> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38671] pathlib.Path.resolve(strict=False) returns relative path on Windows if the entry does not exist
Change by Barney Gale : -- nosy: +barneygale nosy_count: 8.0 -> 9.0 pull_requests: +24802 pull_request: https://github.com/python/cpython/pull/26184 ___ Python tracker <https://bugs.python.org/issue38671> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42234] pathlib relative_to behaviour change
Barney Gale added the comment: That does sound pretty useful! I'd be happy to review a PR though I'm not a core dev. -- nosy: +barneygale ___ Python tracker <https://bugs.python.org/issue42234> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42234] pathlib relative_to behaviour change
Barney Gale added the comment: In fact, I think this is a duplicate of issue40358, which has an open PR against it. -- ___ Python tracker <https://bugs.python.org/issue42234> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40358] pathlib's relative_to should behave like os.path.relpath
Barney Gale added the comment: Also requested in #42234. -- nosy: +barneygale ___ Python tracker <https://bugs.python.org/issue40358> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38671] pathlib.Path.resolve(strict=False) returns relative path on Windows if the entry does not exist
Change by Barney Gale : -- pull_requests: +24874 pull_request: https://github.com/python/cpython/pull/26270 ___ Python tracker <https://bugs.python.org/issue38671> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue43757] pathlib: move 'resolve()' logic out of path flavour
Change by Barney Gale : -- pull_requests: +24875 pull_request: https://github.com/python/cpython/pull/26270 ___ Python tracker <https://bugs.python.org/issue43757> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44198] Add flags or function in pathlib.Path
Barney Gale added the comment: My view: I think the existing solution (that you highlight) is sufficiently idiomatic and easy to discover, and doesn't warrant a new argument or function. However, that may change when `Path` is subclassable, for two reasons: 1. You will be able to subclass `Path` and add your own method, which you may find preferable to a helper function. 2. We _may_ add some sort of file type enum that wraps the constants in `stat`. In that case it might be natural to add a `file_type` argument to `iterdir()`. No promises! -- nosy: +barneygale ___ Python tracker <https://bugs.python.org/issue44198> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29249] Pathlib glob ** bug
Change by Barney Gale : -- nosy: +barneygale ___ Python tracker <https://bugs.python.org/issue29249> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44316] Support preserving path meaning in os.path.normpath() and abspath()
New submission from Barney Gale : >>> os.path.normpath('a/./b/../c//.') 'a/c' >>> pathlib.Path('a/./b/../c//.') PosixPath('a/b/../c') pathlib takes care not to change the meaning of the path when normalising. That means preserving '..' entries, as these can't be simplified without resolving symlinks etc. normpath(), on the other handle, /always/ eliminates '..' entries, which can change the meaning of the path. We could add a new argument to `normpath()` and `abspath()` that leaves '..' entries intact. This was closed as "won't fix" back in bpo-2289, but I think it's worth re-considering. This enhancement would be helpful for my longer-term work to make pathlib an OOP wrapper of os + os.path, rather than a parallel implementation. -- components: Library (Lib) messages: 395122 nosy: barneygale priority: normal severity: normal status: open title: Support preserving path meaning in os.path.normpath() and abspath() type: enhancement ___ Python tracker <https://bugs.python.org/issue44316> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29688] Add support for Path.absolute()
Barney Gale added the comment: Hi - please could a core dev review PR 26153? It adds documentation and tests for Path.absolute(). Thank you! -- ___ Python tracker <https://bugs.python.org/issue29688> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44316] Support preserving path meaning in os.path.normpath() and abspath()
Change by Barney Gale : -- keywords: +patch pull_requests: +25279 stage: -> patch review pull_request: https://github.com/python/cpython/pull/26694 ___ Python tracker <https://bugs.python.org/issue44316> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44316] Support preserving path meaning in os.path.normpath() and abspath()
Barney Gale added the comment: Thanks Terry, I've added a topic here: https://discuss.python.org/t/pathlib-and-os-path-code-duplication-and-feature-parity/9239 The bit about `normpath()` is towards the middle of the post. -- ___ Python tracker <https://bugs.python.org/issue44316> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44316] Support preserving path meaning in os.path.normpath() and abspath()
Barney Gale added the comment: For this bug specifically, the pathlib docs describe the desirable behaviour: Spurious slashes and single dots are collapsed, but double dots ('..') are not, since this would change the meaning of a path in the face of symbolic links: >>> PurePath('foo//bar') PurePosixPath('foo/bar') >>> PurePath('foo/./bar') PurePosixPath('foo/bar') >>> PurePath('foo/../bar') PurePosixPath('foo/../bar') (a naïve approach would make PurePosixPath('foo/../bar') equivalent to PurePosixPath('bar'), which is wrong if foo is a symbolic link to another directory) -- ___ Python tracker <https://bugs.python.org/issue44316> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44403] Add os.path.isreserved() function
New submission from Barney Gale : Windows reserves certain filenames like 'NUL'. Checking for these names is part of a small handful of functionality that is available in pathlib but not in os.path. I propose that we add an os.path.isreserved() function, encorporating Eryk Sun's work on bpo-27827. We then adjust pathlib to call the new function. By doing so, we move one of the few remaining OS-specific implementations in pathlib to low-level libraries (posixpath, ntpath) where it arguably belongs. We also make this functionality available to the segment of people using traditional string-based path operations who don't want to dip their toes into pathlib just for reserved names. -- components: Library (Lib) messages: 395702 nosy: barneygale priority: normal severity: normal status: open title: Add os.path.isreserved() function type: enhancement ___ Python tracker <https://bugs.python.org/issue44403> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27827] pathlib is_reserved fails for some reserved paths on Windows
Change by Barney Gale : -- nosy: +barneygale nosy_count: 6.0 -> 7.0 pull_requests: +25283 stage: -> patch review pull_request: https://github.com/python/cpython/pull/26698 ___ Python tracker <https://bugs.python.org/issue27827> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27827] pathlib is_reserved fails for some reserved paths on Windows
Barney Gale added the comment: I've put Eryk's patch up as a PR: https://github.com/python/cpython/pull/26698 -- ___ Python tracker <https://bugs.python.org/issue27827> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44316] Support preserving path meaning in os.path.normpath() and abspath()
Barney Gale added the comment: I think I agree How would you feel about two new arguments? Following `os.curdir` and `os.pardir` names: def normpath(path, *, keep_curdir=False, keep_pardir=False) ... -- ___ Python tracker <https://bugs.python.org/issue44316> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39950] Add pathlib.Path.hardlink_to()
Change by Barney Gale : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed versions: +Python 3.10 -Python 3.9 ___ Python tracker <https://bugs.python.org/issue39950> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com