[issue40038] pathlib: remove partial support for preserving accessor when modifying a path

2021-04-07 Thread Steve Dower


Change by Steve Dower :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40038] pathlib: remove partial support for preserving accessor when modifying a path

2021-04-06 Thread Steve Dower


Steve Dower  added the comment:


New changeset 2219187cab6bca009c42b63b2f4c30b5b10c916d by Barney Gale in branch 
'master':
bpo-40038: pathlib: remove partial support for preserving accessor when 
modifying a path (GH-19342)
https://github.com/python/cpython/commit/2219187cab6bca009c42b63b2f4c30b5b10c916d


--
nosy: +steve.dower

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40038] pathlib: remove partial support for preserving accessor when modifying a path

2020-04-03 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +18706
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/19342

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40038] pathlib: remove partial support for preserving accessor when modifying a path

2020-03-21 Thread Barney Gale


New submission from Barney Gale :

`pathlib.Path._init()` accepts a 'template' argument that pathlib uses - in 
some cases - to preserve the current accessor object when creating modified 
path objects. This works for `resolve()`, `absolute()` and `readlink()`, *but 
no other cases*!

As customizing the accessor is not something we support (yet! see 
https://discuss.python.org/t/make-pathlib-extensible/3428), and the majority of 
path methods do not call `_init()` with a 'template' argument (and so do not 
preserve the accessor), I suggest this internal functionality be removed. 
Together with bpo-39682 / gh-18846, I believe this would allow us to remove 
`Path._init()` entirely, which would be a small performance win and a 
simplification of the code.

Demo:

```
import pathlib


class CustomAccessor(pathlib._NormalAccessor):
pass


def print_accessor(path):
if isinstance(path._accessor, CustomAccessor):
print("%r: custom" % path)
else:
print("%r: normal" % path)


print("Here's a path with a custom accessor:")
p = pathlib.Path("/tmp")
p._accessor = CustomAccessor()
print_accessor(p)

print("Our accessor type is retained in resolve(), absolute() and readlink():")
print_accessor(p.absolute())
print_accessor(p.resolve())
#print_accessor(p.readlink())

print("But not in any other path-creating methods!")
print_accessor(p.with_name("foo"))
print_accessor(p.with_suffix(".foo"))
print_accessor(p.relative_to("/"))
print_accessor(p / "foo")
print_accessor(p.joinpath("foo"))
print_accessor(p.parent)
print_accessor(p.parents[0])
print_accessor(list(p.iterdir())[0])
print_accessor(list(p.glob("*"))[0])
print_accessor(list(p.rglob("*"))[0])
#print_accessor(p.expanduser())
```

--
components: Library (Lib)
messages: 364783
nosy: barneygale
priority: normal
severity: normal
status: open
title: pathlib: remove partial support for preserving accessor when modifying a 
path
type: performance
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com