-
Notifications
You must be signed in to change notification settings - Fork 41
Support assignment expressions (i.e. the ":=" operator) #195
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
Michael Howitz wrote at 2020-4-24 07:20 -0700:
@d-maurer Thank you for your PR. There is already a similar one: #175 I prefer the implementation you did over the one over there, but I'd like to see a test both for the happy code path and for the exception to make sure it will run successfully in future Python versions.
Currently, `RestrictedPython` has no tests at all.
`AccessControl` contains very limited tests for `RestrictedPython`.
A comment suggests that their purpose is not to seriously test
`RestrictedPython` but to verify that Python works at all
with the `RestrictedPython` policy provided by `AccessControl`.
Currently, the path for the exception cannot be achieved with
Python code (due to Python concrete grammar restrictions);
direct "AST" manipulation would be necessary.
|
@icemac I have added the wanted tests. I am not sure, however, whether you will like their location: I have put them into |
@d-maurer In RestrictedPython we decided to put the tests outside the There are already helpers for determining the Python version in https://github.com/zopefoundation/RestrictedPython/blob/master/src/RestrictedPython/_compat.py |
Michael Howitz wrote at 2020-5-8 07:19 -0700:
@d-maurer In RestrictedPython we decided to put the tests outside the `src` directory
Why?
It means:
* the tests are not installed by a regular installation;
you need a source installation (or "git checkout") to see them
* it makes `RestrictedPython` special: it is the first package I met
where the tests are not a regular submodule/subpackage
* you need a rarely used `zope.testrunner` option (`--test-path`)
that it finds the tests
...
I do not understand what you mean be the configuration magic happening.
I tried to run the tests via `zope.testrunner` - and it found nothing.
I saw that the "github" tests found tests. I looked at `tox.ini`
to find out how this is possible and did not understand it.
I concluded that some "configuration magic" must be at work.
|
Apparently, the |
I agree that the way this package is structured is a mess. I can't even figure out how to run |
If you look into @icemac can you look/review again so we can move forward? |
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.
@dataflake You are right this package is special – you can call it a mess. The idea behind this package was to use some more modern approaches. (The one moving the tests outside one |
The main issue I see is that it uses tools and configurations that are completely out of step with all other packages. Approaching this package and helping out here is unnecessarily hard. |
Assignment expressions are helpful to get clearer and more concise code (in many situations).
Because the Python grammar allows only simple identifiers as target of those expressions, they should be safe (at least) in all contexts that allow assignments of the form
variable = expr
.The Python (3.8) concrete grammar allows only
identifier
as target of assignment expressions; the abstract grammar, however, allows arbitrary expressions. This PR records an error when the target is not aName
(which corresponds toidentifier
in the concrete grammar) -- special handling would be necessary for more general targets.