-
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
Update __init__.py #11
Conversation
Only store the fields used by the traceback system for error reporting on the fake dict object. Change Frame f_globals initialization to only iterate over 2 items instead of all the globals. Just use the standard Exception instead of __traceback_maker as it does nothing special. Use the argcounts from the compiled code object (they will always be 0) since it is more readable. Add an empty __slots__ to the _AttrDict to improve performance. Add a few trailing commas where it makes sense to have them.
Add missing newline
Update to_dict example to fix unit tests
Edited CodeType invocation to match the arguments used in jinja2 debug.py. I'm not entirely clear on why they do / don't copy over certain arguments, but I'm guessing this will give the best compatibility.
(k, v) | ||
for k, v in frame.f_globals.items() | ||
if k in ("__file__", "__name__") | ||
(k, frame.f_globals[k]) |
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.
Can you undo this? Doesn't seem to improve anything?
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.
Sure, I just figured that this was O(1) instead of O(n) on the number of items in the globals dict.
I've added 2 comments. Otherwise I like the changes. |
revert changes to Frame f_globals initialization.
def __getattr__(self, attr): | ||
return self[attr] | ||
|
||
|
||
class __traceback_maker(Exception): |
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 my intention was to use a specific exception (instead of a generic one) because I wanted to aid debugging. Eg, if there's a failure somewhere and the user gets to see it then it's easy to search for it. Not so for the generic Exception
.
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.
Did this custom exception create a problem for you or what warranted its removal?
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.
No real problem, I'll go ahead and add it back in as the debugging thing is actually a good point. Checking the exception type could have been useful in debugging this very issue (and was how I noticed the nlocals thing), so I'll put it back.
Put `__traceback_maker` back in
Cool, all the comments should be addressed now, and the pull request has been reduced to really the core change (plus the one |
Awesome. Can you also update |
Added Patches section, and added code contributers
Cool, I added a patches section and threw in everybody I could find that had contributed to the code, and what they had done. |
fixes #10
__slots__
to the _AttrDict to improve performance.