-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[input]Fix FileNotFoundError when sys path doesn't exist #5535
Conversation
Thanks for opening your first pull request here! 💖 Please check out our contributing guidelines. |
Ref e18cd35#diff-2eeaed663bd0d25b7e608891384b7298 try to use Also, shouldn't you instead just return |
All good points ;) Updated the fix based on comments (squashed commits as well, sorry about that). |
Fixed whitespace Updated based on comments from PR
Thanks you! |
Congrats on merging your first pull request! 🎉🎉🎉 |
line = "0" | ||
try: | ||
line = read_line(path) | ||
except OSError: |
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.
Is this not throwing a IOError
(python2) or FileNotFoundError
(python3) instead?
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.
I think it returns OSError for Windows, but I'm not sure if OSError is the parent or IOError, sooo... test or check with cpython source I'd say :) It should handle FNF in either case for py3 iirc.
Edit: I'd add it, so that it's a tuple with IO and OS errors caught.
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! Yes at the same time I'm getting confused by other commits d80528b which seems to tackle it, but I didn't investigate why I don't see it in the code base.
In the meantime, this is what I have on Linux (python2 and python3):
[andre:/tmp] 2 $ python2 -c "open('/does_not_exist/')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
IOError: [Errno 2] No such file or directory: '/does_not_exist/'
[andre:/tmp] 1 $ python3 -c "open('/does_not_exist/')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '/does_not_exist/'
[andre:/tmp] 1 $
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.
@AndreMiras This resolves FNF → https://github.com/python/cpython/blob/621cebe81b1e6c8de10425955bf532d31ee4df42/Objects/exceptions.c#L1256 (OSError
), for the rest just append IOError if it still brags :)
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.
Oh didn't know about that thingy. Thanks
This is intended to fix #5534
You get a FileNotFoundError when trying to access '/sys/class/input/event/device/capabilities/abs' when the full path doesn't exist.
This may be an input device, but capabilities aren't listed so the fix just defaults "0".