-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
invoke: Update Context.cd() to accept a pathlib.Path or a string
#9823
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
Conversation
This matches the (unreleased) type hints for invoke: https://github.com/pyinvoke/invoke/blob/e95631215fac9ef454f064e2a701f8fce351752d/invoke/context.py#L346
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like the runtime implementation is incorrect. They're calling str() on the path argument here, rather than os.fspath. That means that the function will work with str and pathlib.Path objects, but it won't actually work with arbitrary os.PathLike objects, even if that's what the type hints in the upstream source code say. So maybe the type hint should actually be str | pathlib.Path rather than StrPath.
(Upstream should probably update their implementation so that it calls os.fspath() rather than str() on the path parameter. Then the implementation would match the type hint that they've provided.)
This comment has been minimized.
This comment has been minimized.
Ooh, good catch. I'll open a PR upstream to fix that. |
AlexWaygood
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Context.cd() to accept an os.PathLike or a stringContext.cd() to accept a pathlib.Path or a string
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Issue found when fixing the type hint in typeshed: python/typeshed#9823 (review)
This matches the (unreleased) type hints for invoke: https://github.com/pyinvoke/invoke/blob/e95631215fac9ef454f064e2a701f8fce351752d/invoke/context.py#L346