GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||
GeezerVison is showing github.com — Adjust shutil.move stubs to allow bytes/Pathlike[bytes] args by jpy-git · Pull Request #6832 · python/typeshed Conversation
Contributor
Closes #6831. Thorough example included in the issue. TLDR:
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
jpy-git
commented
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI the linked bug applies to >>> import shutil >>> shutil.move(b"test1.txt", b"test2.txt") 'test2.txt'
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
This comment has been minimized.
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
This def works for me: >>> import shutil >>> shutil.move("test.txt", b"test2.txt") b'test2.txt' >>> shutil.move(b"test2.txt", "test.txt") 'test.txt' >>> shutil.move("some_folder", "some_folder2") 'some_folder2' >>> shutil.move(b"some_folder2", b"some_folder") b'some_folder' >>> shutil.move(b"some_folder", "some_folder2") 'some_folder2' >>> shutil.move("some_folder2", b"some_folder") b'some_folder' EDIT: I noticed that bit in the source code only impacts directories, so I've added them above. They still seem to work though. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The code I mentioned runs when |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Ahh it's only when In that case yes I get errors: Feels like a bug given that it's only in this section of the code... |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The second of those issues seems like a bigger issue since this would also fail: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
With those test cases, I think we should close this PR since bytes will always break the existing folder case. Do you happen to know where the best place flag this issue is for cpython? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Edit: disregard my comment, I just pattern matched to a thing I'd seen before (shutil has historically not supported path objects well, in general worth double checking these kinds of changes against older Pythons) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
No worries, it looks like the types I'm working through the other In the meantime, maybe it's worth me removing my changes and just adding a comment above the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
That seems right to me. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I've reverted the typing changes and added a comment linking to this PR to highlight for future contributors 👍 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
These paths can flow into `shutil.move`, which does not accept byte paths or (int) file descriptors. See python/typeshed#6832
* Fix type hint for load_dotenv Fixes #431 * Quote type hints to avoid runtime errors in earlier Python versions * Revise type of dotenv_path parameter Based on PR feedback and typeshed's type hint for the built-in open() function: https://github.com/python/typeshed/blob/e2d67bf7034f68c07bd35150247e58e0817725d9/stdlib/builtins.pyi#L1421 * Allow only string paths, not byte paths These paths can flow into `shutil.move`, which does not accept byte paths or (int) file descriptors. See python/typeshed#6832 * Create a type alias for the paths this library accepts And use it consistently in main.py.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
shutil.move stub does not account for bytes paths
There was an error while loading. Please reload this page.