-
Couldn't load subscription status.
- Fork 42
Port eval py #43
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
Port eval py #43
Conversation
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.
LGTM
|
@stephan-hof could you please rebase and merge afterwards |
3815ba2 to
2f572d2
Compare
This gets rid of the dependency to know how the bytecode looks like.
I guess this particular code was used at the early days of restricted python. To see the speed penaltiy. However I cannot see how this can be utilized by other libraries.
* Using `keys` is not modern anymore. * Using `has_key` is not modern anymore. * Proper variable names * Comments in the same line is not very pep8.
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.
See the question I had.
| if self.ucode is None: | ||
| # Use the standard compiler. | ||
| co = compile(self.expr, '<string>', 'eval') | ||
| exp_node = compile( |
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.
Is prepUnrestrictedCode actually still needed?
I think getting SyntaxErrors and used names can be done by compile_restricted_eval.
Or do I miss something here?
(Maybe this can be delayed after the release to stay backwards compatible to see if some code uses this method or the ucode attribute.)
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.
You are right, the only justification for this method is the ucode attribute.
I did a quick search and found one user of it: https://github.com/zopefoundation/DocumentTemplate/blob/6b526d4b76f5496de5049f365a09ab712751c532/src/DocumentTemplate/DT_Util.py#L212
My suggestion would be to keep this method and ucode. To stay backwards compatible.
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.
Okay.
This ports
Eval.pyto python3 by using the methods fromcompile.py.As a side effect I brought back support for
used_namesinRestrictingNodeTransformer.I know nowadays
used_namescould have been aset(), but I didn't dare to change the API.Since
used_namesis used by other code outside of RestrictedPython.