-
Notifications
You must be signed in to change notification settings - Fork 202
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
Should invalid code be representable? #287
Comments
As one of the main usecases of LibCST is to be able to construct source code, I think it should catch these kinds of errors. Bug or not, IMO it's worth addressing this :) |
Those cases can be rejected by updating corresponding |
sk-
added a commit
to sk-/LibCST
that referenced
this issue
Jul 12, 2020
For `Try` statements we ensure that the bare except, if present, is at the last position. For ImportAlias we ensure that the imported name is valid. Fixes Instagram#287
jimmylai
added a commit
that referenced
this issue
Jul 14, 2020
* fix: improve validation for ImportAlias and Try statements For `Try` statements we ensure that the bare except, if present, is at the last position. For ImportAlias we ensure that the imported name is valid. Fixes #287 * Apply suggestions from code review Add missing periods. * Apply suggestions from code review Add missing periods. * Update libcst/_nodes/tests/test_import.py Co-authored-by: jimmylai <yurinai@gmail.com>
This was referenced Apr 19, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there! I've been working on Zac-HD/hypothesmith#2, generating random CSTs in order to turn them back in to Python source code and
ruin someone's dayhelp test parsers, autoformatters, and so on. LibCST has been fantastic for this - thanks so much!In the process, I've encountered two cases where Hypothesmith generated a valid CST and could convert this to source code, but calling
compile
on the result gave aSyntaxError
:In the first case, the float
0.
needs to be in parens. For the second,Try._validate
would need to reject multipleexcept:
handlers, or handlers whereexcept:
is present but not the last handler listed.I don't know whether these odd behaviour will be considered a bug, since my use-case is quite unusual and I can work around them fairly easily, but it seemed worth reporting. If you do want to have
_validate
reject all invalid code though, I can definitely help find those cases 😅The text was updated successfully, but these errors were encountered: