[issue38222] pathlib Path objects should support __format__

2021-09-13 Thread Antoine Pitrou
Antoine Pitrou added the comment: I would be in favour of adding Path.__format__, even though I'm not terribly convinced by the use case presented. -- ___ Python tracker ___

[issue38222] pathlib Path objects should support __format__

2021-09-13 Thread Eric V. Smith
Eric V. Smith added the comment: > log_dir = Path('logs/{date}') > log_file = Path(str(path).format(time.strftime('%Y-%m-%d')) / 'log.txt' (I think you're missing "date=" in the call to .format().) Could you show what you think this would look like if Path.__format__ existed? I don't think

[issue38222] pathlib Path objects should support __format__

2021-09-13 Thread Richard
Richard added the comment: Sorry, that should have been: log_dir = Path('logs/{date}') -- ___ Python tracker ___ ___

[issue38222] pathlib Path objects should support __format__

2021-09-13 Thread Richard
Richard added the comment: I would like for this to be reconsidered. Yes, you can use str(), but converting back and forth becomes really clunky: log_dir = 'logs/{date}' log_file = Path(str(path).format(time.strftime('%Y-%m-%d')) / 'log.txt' -- nosy: +nyuszika7h

[issue38222] pathlib Path objects should support __format__

2021-04-22 Thread miss-islington
Change by miss-islington : -- pull_requests: +24267 pull_request: https://github.com/python/cpython/pull/25542 ___ Python tracker ___

[issue38222] pathlib Path objects should support __format__

2021-04-22 Thread Steve Dower
Change by Steve Dower : -- pull_requests: -24264 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue38222] pathlib Path objects should support __format__

2021-04-22 Thread Steve Dower
Change by Steve Dower : -- pull_requests: -24263 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue38222] pathlib Path objects should support __format__

2021-04-22 Thread Steve Dower
Steve Dower added the comment: New changeset e07d8098892e85ecc56969d2c9a5afb3ea33ce8f by Steve Dower in branch 'master': bpo-38222: Check specifically for a drive, not just a colon (GH-25540) https://github.com/python/cpython/commit/e07d8098892e85ecc56969d2c9a5afb3ea33ce8f --

[issue38222] pathlib Path objects should support __format__

2021-04-22 Thread miss-islington
Change by miss-islington : -- pull_requests: +24264 pull_request: https://github.com/python/cpython/pull/25543 ___ Python tracker ___

[issue38222] pathlib Path objects should support __format__

2021-04-22 Thread miss-islington
Change by miss-islington : -- nosy: +miss-islington nosy_count: 6.0 -> 7.0 pull_requests: +24263 pull_request: https://github.com/python/cpython/pull/25542 ___ Python tracker

[issue38222] pathlib Path objects should support __format__

2021-04-22 Thread Steve Dower
Change by Steve Dower : -- pull_requests: -24260 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue38222] pathlib Path objects should support __format__

2021-04-22 Thread Steve Dower
Change by Steve Dower : -- nosy: +steve.dower nosy_count: 5.0 -> 6.0 pull_requests: +24260 pull_request: https://github.com/python/cpython/pull/25540 ___ Python tracker ___

[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Brett Cannon
Brett Cannon added the comment: I'm -1 as PEP 519 created __fspath__ specifically so that pathlib.Path wouldn't be confused as a string by accident. You can also use os.fspath() to get a string representation of the path itself. I also don't know if Antoine wants to make this sort of call

[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Roundup Robot
Change by Roundup Robot : -- pull_requests: +15872 pull_request: https://github.com/python/cpython/pull/16287 ___ Python tracker ___

[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Roundup Robot
Change by Roundup Robot : -- keywords: +patch pull_requests: +15871 stage: -> patch review pull_request: https://github.com/python/cpython/pull/16286 ___ Python tracker ___

[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Miki Tebeka
Miki Tebeka added the comment: I don't think it violates " Explicit is better than implicit." There's a lot of work done to make pathlib.Path objects work in places where str or bytes is expected (e.g PEP 519), IMO this is another case. -- ___

[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Eric V. Smith
Eric V. Smith added the comment: I'm also -0 on it. It's up to Antoine. -- ___ Python tracker ___ ___ Python-bugs-list mailing

[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I am -0 on this. It is a can of worms. Once we add a trivial __format__ in Path, we will need to handle numerous requests for adding a trivial __format__ in many other classes. It is better to teach users to use !s (and this works also on older Python

[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Eric V. Smith
Eric V. Smith added the comment: I don't think anyone is suggesting reverting the decision on object.__format__. That decision should stay. I think the suggestion is to add Path.__format__, which just converts to a string and formats with the given spec. Unless someone can think of a

[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Or use !s or !r. In some cases it may be even better to use both convertions: f'{str(path)!r:>50}'. This is all application specific, so I do not think we should rethink our old decision. Explicit is better than implicit. --

[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Eric V. Smith
Eric V. Smith added the comment: Correct: this change was made specifically so that objects could add their own format specifiers at a later time. If I recall correctly, This change was precipitated by wanting to add datetime.__format__: this change broke existing uses for format() that

[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Initially, the default __format__ converted the object to str and passed format specifier to str.__format__. This is defined in PEP 3101: class object: def __format__(self, format_spec): return format(str(self), format_spec) But later we

[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Eric V. Smith
Eric V. Smith added the comment: I agree with Serhiy that !s solves the problem. But as a convenience it might be nice to add __format__. This issue pops up from time to time on Path and other types, and I don't think !s is very discoverable. Especially because formatting works with a

[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Convert it to string first: print(f'path is: {path!s:>50}') -- nosy: +serhiy.storchaka ___ Python tracker ___

[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +pitrou ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Miki Tebeka
New submission from Miki Tebeka : Currently pathlib.Path cannot be used with string formatting directives. IMO it should. >>> from pathlib import Path >>> path = Path('/path/to/enlightenment') >>> print(f'path is: {path:>50}') Traceback (most recent call last): File "", line 1, in