[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-09-06 Thread Andrei Kulakov
Andrei Kulakov added the comment: To be more precise, this change fixes https://bugs.python.org/issue41082 by raising RuntimeError instead of KeyError and also by documenting it, which means matplotlib can fix it by either using os.path.expanduser or catching RuntimeError, whichever might

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-09-06 Thread Andrei Kulakov
Andrei Kulakov added the comment: Note this change also fixes https://bugs.python.org/issue41082 . I'm guessing it's too much of an edge case to backport this fix to 3.9, so I've put up a possible fix via docs update on that issue. -- nosy: +andrei.avk, kj

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-09 Thread Steve Dower
Change by Steve Dower : -- stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___ Python-bugs-list

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-09 Thread Steve Dower
Steve Dower added the comment: New changeset ba1db571987c65672d9c06789e9852313ed2412a by Barney Gale in branch 'master': bpo-39899: Don't double-check directory name if we're requesting the current user's home directory in ntpath.expanduser() (GH-25277)

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-08 Thread Barney Gale
Barney Gale added the comment: Good spot Eryk - I've put in another PR to address it. -- ___ Python tracker ___ ___

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-08 Thread Barney Gale
Change by Barney Gale : -- pull_requests: +24014 stage: resolved -> patch review pull_request: https://github.com/python/cpython/pull/25277 ___ Python tracker ___

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-08 Thread Eryk Sun
Eryk Sun added the comment: > os.path.expanduser() has many flaws, and it just "guess" the > home directory for other users. I'm fine with not guessing another user's profile directory (or home directory) in some cases, or even always. But the code that got committed bails out even if the

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: AFAIK you can set arbitrary path as user home directory. So home directories of different users can even not be on the same disk, and the last component of the path can be different from the user name. os.path.expanduser() has many flaws, and it just

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-07 Thread Eryk Sun
Eryk Sun added the comment: For a "~user" path, the value of userhome should always be used if target_user == current_user. If for some reason the USERPROFILE environment variable isn't defined, the fallback "%HOMEDRIVE%%HOMEPATH%" does not necessarily end in the user's name. Example

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-07 Thread Steve Dower
Change by Steve Dower : -- resolution: -> fixed status: open -> closed ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-07 Thread Steve Dower
Steve Dower added the comment: New changeset 3f3d82b84823eb28abeedf317bbe107bbe7f6492 by Barney Gale in branch 'master': bpo-39899: os.path.expanduser(): don't guess other Windows users' home directories if the basename of the current user's home directory doesn't match their username.

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-07 Thread Barney Gale
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

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-07 Thread Steve Dower
Steve Dower added the comment: > Firstly, `os.path.expanduser()` is already documented to return the path > unchanged if the home directory can't be resolved: Ah, too bad. Doesn't prevent us from changing it, but hopefully it means that everyone using it is already checking the result and

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-07 Thread Barney Gale
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

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-07 Thread Steve Dower
Steve Dower added the comment: I think this is worth unifying, but I'm concerned about making expanduser() return the original path on Windows - "~name" is a valid filename/relative path, and so code that does mkdir(expanduser("~nonuser/dir")) could create garbage in the current directory.

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2020-03-08 Thread Barney Gale
Barney Gale added the comment: The only design flaw mentioned in that thread is that `os.path.expanduser()` returns the input unchanged if expansion fails, which is not very pythonic. However, such a problem doesn't necessitate a rewrite of `os.path.expanduser()`. Checking `result[:1]` is

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2020-03-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: It was discussed in issue19776. Having separate implementation we can avoid design flaws of os.path.expanduser(). -- ___ Python tracker

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2020-03-08 Thread Barney Gale
Barney Gale added the comment: I see no reason for the duplication, and I can point to one concrete bug affecting your re-implementation of `expanduser` that doesn't affect the original, i.e. that a `KeyError` is raised on Windows when `"USERNAME"` is not present in `os.environ`, whereas

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2020-03-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I see no reason to change the current code. -- resolution: -> not a bug stage: patch review -> resolved status: open -> closed ___ Python tracker

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2020-03-07 Thread Barney Gale
Change by Barney Gale : -- keywords: +patch pull_requests: +18198 stage: -> patch review pull_request: https://github.com/python/cpython/pull/18841 ___ Python tracker ___

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2020-03-07 Thread Barney Gale
Barney Gale added the comment: We can check whether `os.path.expanduser()` returned a path beginning with "~" and raise a RuntimeError if so, right? On point #2, I'm not sure this optimization alone justifies the duplication. PR incoming... --

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2020-03-07 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: There are two reasons: 1. os.path.expanduser() returns the path unchanged when a home directory cannot be resolved, pathlib.Path.expanduser() raises an error. The latter behavior looks more robust, but we can't change os.path.expanduser(). 2.

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2020-03-07 Thread Barney Gale
New submission from Barney Gale : `pathlib.Path.expanduser()` does not call `os.path.expanduser()`, but instead re-implements it. The implementations look pretty similar and I can't see a good reason for the duplication. The only difference is that `pathlib.Path.expanduser()` raises