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
os.path.ismount sometimes raises FileNotFoundError on Windows #73045
Comments
It returns True for drives which don't exist and raises for paths starting with drives which don't exist. >>> os.path.exists("C:\\")
True
>>> os.path.ismount("C:\\")
True
>>> os.path.ismount("C:\\doesnotexist")
False
>>> os.path.exists("F:\\")
False
>>> os.path.ismount("F:\\")
True
>>> os.path.ismount("F:\\doesnotexist")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\lazka\AppData\Local\Programs\Python\Python35\lib\ntpath.py", line 290, in ismount
return path.rstrip(seps) == _getvolumepathname(path).rstrip(seps)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'F:\\doesnotexist' |
Traditionally we handle exceptions in os.path.is* functions and return False. |
I would like to take this issue as my first issue to start contributing to Python development. |
I am going to think maybe it was the "os.path.ismount" command that is causing the issue. Does the file exist? |
If the file does not exist, it is definitely not a mount point. So the function should return False instead of raising an error. |
Nishant Misra are you still working on this issue, if not could I take it from now on, as my first issue and contribution to Python? |
Yes Lahfa Samy, you can take it up. I did not work on the issue. |
I submitted a PR and get reviewed by @lazka. Is there anything I should do for pushing it to next step? |
Reminding us on here is helpful (for me, anyway). I just left a couple of suggestions to make sure we handle all the cases. It's important when you change or add tests that you make sure the test fails without your fix - otherwise it might not be testing the fix! |
s I have tried to workout a solution for the problem. Below is my observation and possible solution. os.path.ismount("F:\\doesnotexist") Exception occurs for the above line if the system fails to find both drive and the path that follows it. A 'FileNotFoundError' exception is thrown. If we can handle this exception and return false for method ismount(), then problem can be resolved. I changed the existing code ismount method and it is working. Changed Code=> Please check, if this solution is correct. |
@steve.dower, please review the changes when you get a chance. Thanks! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: