Skip to content

Fix target argument of pathlib.Path.{sym,hard}link_to #10019

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

Merged
merged 1 commit into from
Apr 13, 2023

Conversation

viccie30
Copy link
Contributor

@viccie30 viccie30 commented Apr 7, 2023

The underlying os.{sym,}link functions take any PathLike object:

def symlink(
src: StrOrBytesPath, dst: StrOrBytesPath, target_is_directory: bool = False, *, dir_fd: int | None = None
) -> None: ...
,
def link(
src: StrOrBytesPath,
dst: StrOrBytesPath,
*,
src_dir_fd: int | None = None,
dst_dir_fd: int | None = None,
follow_symlinks: bool = True,
) -> None: ...
.

@viccie30 viccie30 force-pushed the fix-pathlib-link-args branch from 254c007 to ebc0ebd Compare April 7, 2023 00:19
@github-actions

This comment has been minimized.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just like in os, we should just use _typeshed.StrOrBytesPath here.

@AlexWaygood
Copy link
Member

AlexWaygood commented Apr 12, 2023

Thanks! Just like in os, we should just use _typeshed.StrOrBytesPath here.

I haven't looked too closely at this PR, but (unlike os), pathlib only supports string paths, not bytes paths, so it should probably be _typeshed.StrPath rather than _typeshed.StrOrBytesPath here?

@srittau
Copy link
Collaborator

srittau commented Apr 12, 2023

The arguments to these functions skip any pathlib handling and just call the underlying functions, so bytes are accepted.

@AlexWaygood
Copy link
Member

The arguments to these functions skip any pathlib handling and just call the underlying functions, so bytes are accepted.

My worry is that even if bytes paths technically work for this method, you probably shouldn't be using bytes paths with anything pathlib-y, it's bound to bite you at some point.

But no strong opinion; happy for us to go with StrOrBytesPath since it is allowed by the implementation, at least at the moment.

@viccie30 viccie30 force-pushed the fix-pathlib-link-args branch 2 times, most recently from 8d54f57 to 39464d1 Compare April 13, 2023 11:28
The underlying os.{sym,}link functions take any StrOrBytesPath.
@viccie30 viccie30 force-pushed the fix-pathlib-link-args branch from 39464d1 to 508f479 Compare April 13, 2023 11:29
@viccie30
Copy link
Contributor Author

I have made the requested change to StrOrBytesPath.

@viccie30 viccie30 requested a review from srittau April 13, 2023 11:30
@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

bandersnatch (https://github.com/pypa/bandersnatch)
+ src/bandersnatch_storage_plugins/swift.py: note: In member "symlink_to" of class "SwiftPath":
+ src/bandersnatch_storage_plugins/swift.py:415: error: Signature of "symlink_to" incompatible with supertype "Path"  [override]
+ src/bandersnatch_storage_plugins/swift.py:415: note:      Superclass:
+ src/bandersnatch_storage_plugins/swift.py:415: note:          def symlink_to(self, target: Union[str, bytes, PathLike[str], PathLike[bytes]], target_is_directory: bool = ...) -> None
+ src/bandersnatch_storage_plugins/swift.py:415: note:      Subclass:
+ src/bandersnatch_storage_plugins/swift.py:415: note:          def symlink_to(self, src: Union[Path, str], target_is_directory: bool = ..., src_container: Optional[str] = ..., src_account: Optional[str] = ...) -> None

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@srittau srittau merged commit 8db375c into python:main Apr 13, 2023
@viccie30 viccie30 deleted the fix-pathlib-link-args branch April 13, 2023 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants