-
Notifications
You must be signed in to change notification settings - Fork 46
Fix problem with objects with invalid repr #1899
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
Conversation
@@ -1,4 +1,4 @@ | |||
mypy==1.0.0 | |||
coverage | |||
utbot-executor==1.1.27 | |||
utbot-executor==1.1.31 |
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 looked this version of utbot_executor and I don't like the way you check whether an object has correct repr:
if not isinstance(py_object, str) and r.startswith('<') and r.endswith('>')
One can override __repr__
method of their (unserializable) object so that it will pass this check.
From CPython sources we see that there is a finite number of types that are not serialized with __reduce__
method: https://github.com/python/cpython/blob/main/Lib/pickle.py#L734
Maybe we should just list them?
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 didn't find socket.socket
and logging.Logger
in this file... For example, logging.Logger
has method __reduce__
but it sometimes raises error pickle.PicklingError
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.
Maybe we can call eval
and check that we got the same type (but not the same value because object can be serializable and incomparable)
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.
But socket.socket
and logging.Logger
can never be serialized by pickle.
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.
eval
check may be tricky because of modules that are needed to be imported
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.
But
socket.socket
andlogging.Logger
can never be serialized by pickle.
I can pickle logging.Logger
:
import logging
import pickle
pickle.dumps(logging.getLogger())
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.
eval
check may be tricky because of modules that are needed to be imported
I agree, it can be a problem
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.
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 added list of repr
-able objects from pickle source code (tamarinvs19/utbot_executor@e6dc858)
* add list of `repr`-able types * add attempt to call `repr . evel . repr` and compare with `repr`
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.
|
Description
Fix problem with serialization of "unserializable" objects (for example,
logging.Logger
orsocket.socket
). We cannot serialize it so cannot generate tests but in previous version we generated tests with string representation of these objects (<Logger x (NOSET)>
or<socket.socket ... >
).In future we can use mocks at these situations.
Fixes #1822
How to test
Manual tests
See #1822 (comment)
Expected: no one test have been generated
Self-check list
Check off the item if the statement is true. Hint: [x] is a marked item.
Please do not delete the list or its items.