Skip to content

gh-117352: Handle /:/ for ntpath.isabs #117362

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

Closed
wants to merge 6 commits into from

Conversation

nineteendo
Copy link
Contributor

@nineteendo nineteendo commented Mar 29, 2024

Benchmark:

# test.sh
python -m timeit -s "import before.ntpath" "before.ntpath.isabs('C:/foo')"
python -m timeit -s "import after.ntpath" "after.ntpath.isabs('C:/foo')"
500000 loops, best of 5: 398 nsec per loop # before
500000 loops, best of 5: 469 nsec per loop # after
# -> 1.18x slower

@nineteendo nineteendo mentioned this pull request Mar 29, 2024
16 tasks
@nineteendo nineteendo marked this pull request as ready for review March 29, 2024 07:43
@eryksun eryksun requested review from barneygale and zooba March 29, 2024 12:03
Co-Authored-By: Barney Gale <barney.gale@gmail.com>
@nineteendo nineteendo changed the title gh-117352: Handle /: for ntpath.isabs gh-117352: Handle /:/ for ntpath.isabs Mar 31, 2024
@nineteendo
Copy link
Contributor Author

I've reverted the slicing. The speed decrease of str.startswith() should be fixed soon.

@zooba
Copy link
Member

zooba commented Apr 2, 2024

Why would we handle /: differently from any other invalid drive character? Is there some important reason to do this as opposed to more thoroughly checking for all invalid paths?

@nineteendo
Copy link
Contributor Author

#101363 (comment):

WinAPI GetFullPathNameW() will accept any character in the 16-bit BMP as a drive 'letter', except for null, slash, and backslash.

You could restrict it further, but that would make the code more complicated.

@nineteendo nineteendo closed this Apr 5, 2024
@nineteendo nineteendo deleted the fix-ntpath.isabs branch April 5, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants