Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pathlib.Path.symlink_to() returns None instead of a valid object #118704

Closed
adventurecomputer opened this issue May 7, 2024 · 4 comments
Closed
Labels
topic-pathlib type-feature A feature request or enhancement

Comments

@adventurecomputer
Copy link

adventurecomputer commented May 7, 2024

Bug report

Bug description:

# Add a code block here, if required
from pathlib import Path
source=Path('link')
target=Path('target')
link=source.symlink_to(target)

print(link) # returns None

link is supposed to be a newly created symlink object.

CPython versions tested on:

3.8

Operating systems tested on:

Linux

@adventurecomputer adventurecomputer added the type-bug An unexpected behavior, bug, or error label May 7, 2024
@eryksun eryksun added topic-pathlib type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels May 7, 2024
@eryksun
Copy link
Contributor

eryksun commented May 7, 2024

The symlink_to() and hardlink_to() methods create a symlink or hardlink in the filesystem, but they do not return a Path object for it. This could be new behavior for a feature enhancement in Python 3.14, but it's not a bug.

@barneygale
Copy link
Contributor

pathlib doesn't return self to facilitate method chaining at the moment. I'd rather not add support because it doesn't seem necessary and complicates the API slightly. But I'll keep an open mind if you'd like to put together a rationale @adventurecomputer!

@eryksun
Copy link
Contributor

eryksun commented May 7, 2024

pathlib doesn't return self

Maybe returning a Path is a good idea here, but I don't think returning self is generally a good idea, unless it's an absolute path. The working directory could change, but for sure the returned Path should always refer to the symlink or hardlink that was created in the filesystem.

@adventurecomputer
Copy link
Author

I was testing codellama in my workflow, and this snippet came up as one of the suggestions. It seemed reasonable to assume the pattern of <returned object> = <object>.instance_method() was being followed and using pydoc the results don't show types of the return, so I assumed this was the case.

@erlend-aasland erlend-aasland closed this as not planned Won't fix, can't repro, duplicate, stale May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-pathlib type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants