Skip to content
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

Merged
merged 7 commits into from
Dec 17, 2015
Merged

Update __init__.py #11

merged 7 commits into from
Dec 17, 2015

Conversation

DRayX
Copy link
Contributor

@DRayX DRayX commented Dec 17, 2015

fixes #10

  • Only store the fields used by the traceback system for error reporting on the fake code object.
  • Change fields used to create real code objects to match those used by jinja2.
  • Add an empty __slots__ to the _AttrDict to improve performance.
  • Add a few trailing commas where it makes sense to have them.

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])
Copy link
Owner

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?

Copy link
Contributor Author

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.

@ionelmc
Copy link
Owner

ionelmc commented Dec 17, 2015

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):
Copy link
Owner

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.

Copy link
Owner

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?

Copy link
Contributor Author

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
@DRayX
Copy link
Contributor Author

DRayX commented Dec 17, 2015

Cool, all the comments should be addressed now, and the pull request has been reduced to really the core change (plus the one __slots__ thing), which is sort of nice. I might look into improving some performance stuff (that's what I was playing with in the f_globals thing), but I can make that a separate pull request. Thanks for taking a look at this.

@ionelmc
Copy link
Owner

ionelmc commented Dec 17, 2015

Awesome. Can you also update AUTHORS.rst - I don't know what to put there :)

Added Patches section, and added code contributers
@DRayX
Copy link
Contributor Author

DRayX commented Dec 17, 2015

Cool, I added a patches section and threw in everybody I could find that had contributed to the code, and what they had done.

ionelmc added a commit that referenced this pull request Dec 17, 2015
@ionelmc ionelmc merged commit f15b95c into ionelmc:master Dec 17, 2015
@ionelmc
Copy link
Owner

ionelmc commented Dec 18, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with generators
2 participants