-
Notifications
You must be signed in to change notification settings - Fork 33
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
Deserialize by using __new__ whenever possible #73
base: master
Are you sure you want to change the base?
Conversation
0912b22
to
89cbd73
Compare
211dcff
to
b2764c9
Compare
Applied changes suggested by the check job. |
0fc3000
to
62b857c
Compare
Tests added |
Looks like (first guess) that PyPy does not like test for built-in reducer. I will check it. |
I created a bug report for PyPy pypy/pypy#4026 regarding the builtin method check. For now, we could switch to |
I did what I proposed - there are two more commits, one switching to |
In the PyPy bug report one suggestion was to use |
I am done with this PR. |
15e6274
to
c6c702f
Compare
Squashed related commits, updated reasoning in description and updated naming in code (no functional change, just added one more test). Also added two fixes for the |
78ea010
to
d5713ba
Compare
Rebased to latest master |
Rebased to the latest master and as a bonus fixed build with Python 3.8, 3.9 and 3.10 on macos. Enjoy 😁 |
The doctests weren't being run and had bitrotted. Make them work again.
macos-latest doesn't seem to have working binaries for these.
@oldium not sure if you noticed, but PyPy fixed the isbultin bug you reported. |
@stuaxo Are you sure it is fixed, or you found that the bug is closed? |
This fixes `CoverageWarning: Couldn't parse Python file '.../tests/badsyntax.py' (couldnt-parse)`. Based on a change by Oldřich Jedlička.
@oldium ooh, good point, looking at the ticket again I am not sure - apologies for the noise. |
Using of the class constructor and passing it the args values is not always correct, the custom parameters could be different to the args actually recorded by the built-in Exception class. Try to use the __new__ to create class instance and initialize the args attribute afterwards to prevent calling constructor with wrong arguments. Other instance attributes are initialized in a standard way by pickle module, so this way the reconstruction of the exception is complete. Subclasses of OSError are known exceptions to this, because they initialize read-only attributes from the constructor argument values, so usage of the __new__ factory method leads to lost values of those read-only attributes. Fixes: ionelmc#65 Signed-off-by: Oldřich Jedlička <[email protected]>
…elmc#65 Signed-off-by: Oldřich Jedlička <[email protected]>
Rebased on top of #79 |
Using of the class constructor and passing it the args values is not always correct, the custom parameters could be different to the args actually recorded by the built-in Exception class. Try to use the
__new__
to create class instance and initialize the args attribute afterwards to prevent calling constructor with wrong arguments. Other instance attributes are initialized in a standard way by pickle module, so this way the reconstruction of the exception is complete.Subclasses of OSError are known exceptions to this, because they initialize read-only attributes from the constructor argument values, so usage of the new factory method leads to lost values of those read-only attributes.
Fixes: #65