-
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
Add to_dict method and from_dict classmethod on Tracebacks #5
Conversation
|
Hey, thanks for the PR. Can you also add couple tests for these new functions? |
I actually did add a doctest in README.rst for converting to dict -> json -> dict -> Traceback. I'm not sure why coverage would have decreased, any suggestions for other tests to add? |
Might be caused by these two lines: https://coveralls.io/builds/2214966/source?filename=src%2Ftblib%2F__init__.py#L25 |
('f_globals', dct['tb_frame']['f_globals']), | ||
('f_code', _AttrDict((k, v) for k, v in dct['tb_frame']['f_code'].items())) | ||
)) | ||
frame['f_code']['co_lnotab'] = frame['f_code']['co_lnotab'].encode('latin1') |
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.
Should this be encoded to something else? Like hex
encoding. I doubt latin1
can be used for binary data.
Also, we might not need co_lnotab at all (it just maps bytecode offsets to source linenumbers).
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 still need to test that theory about not needing co_lnotab
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, yeah - I suppose I don't even need that try/except, I just kept it so attr access failures looked a bit more natural.
As for choosing latin1, you could use any one-byte encoding, they're all the same for this. Latin1 is just a pretty common one.
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.
Actually, I just found out 'hex' doesn't work, it requires that you have an even-length bytes to decode.
The tricky part about encoding co_lnotab is that you start with bytes, but json requires unicode. So you have to find an encoding that maps any arbitrary bytes to unicode code points, and then back without any changes. It would definitely be nice if it weren't required.
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 suspect it's not needed at all. Try setting it to ""
(remove it from everywhere).
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.
Alternatively you could convert it to a list of ints, if there's no suitable encoding.
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.
Looks like that worked just fine.
|
1 similar comment
Alright, it's merged now and released on PyPI. Thanks! |
Thank you! I'm looking forward to making use of this, great to have it on pypi. |
This makes it possible to pass tblib.Traceback around as JSON/YAML, and easy to write custom JsonEncoder/JsonDecoder classes for that purpose.