-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add OSError.__reduce__ #4191
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
Add OSError.__reduce__ #4191
Conversation
a00dac2 to
637870a
Compare
vm/src/exceptions.rs
Outdated
| // second exception filename | ||
| "filename2" => ctx.none(), | ||
| "__str__" => ctx.new_method("__str__", excs.os_error, os_error_str), | ||
| "__reduce__" => ctx.new_method("__str__", excs.os_error, os_error_reduce), |
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.
| "__reduce__" => ctx.new_method("__str__", excs.os_error, os_error_reduce), | |
| "__reduce__" => ctx.new_method("__reduce__", excs.os_error, os_error_reduce), |
vm/src/exceptions.rs
Outdated
| if new_args.args.len() >= 2 { | ||
| new_args.args.truncate(2); | ||
| } |
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.
This is a question because I don't know the spec very well. Exceptions usually takes infinite args and store it. What happens for more args than 4 in this case?
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 seems to work that no matter how we put arguments to its parenthesis (work means it does not throw exceptions).
But according to code and behavior. it works as expected when only the given argument length is between 2 and 5.
>>> OSError(1,2).errno
1
>>> OSError(1,2).strerror
2
>>> OSError(1)
OSError(1)
>>> OSError(1).errnohttps://github.com/python/cpython/blob/3.10/Objects/exceptions.c#L820-L876
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.
Let's discuss this point in #4194 ...
df5bca4 to
e7b6f1e
Compare
Tested by removing expected failure and commenting everything but OSError in Lib/test/test_exceptions.py::testAttributes::exceptionList, WindowsError of the test.
Part of #3611