You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have to transform (using a libcst.CSTTransformer) some 3rd party code, which might contain statements like assert("foo") == "foo".
Although this is a valid python code, I get the error libcst._nodes.base.CSTValidationError: Must have at least one space after 'assert'.
I cannot fix this in the leave_Assert hook, as it is called after validation, and I cannot fix it in the visit_Assert hook, as the object node is frozen.
Currently, the only option I can think of is to do a regex search and replace before LibCST to add the missing whitespace and then feed it to my transformer.
Is there any easier way to do this, preferably within LibCST?
The text was updated successfully, but these errors were encountered:
Seems like duplicate of #1095
UPDATE: Okay, maybe it's not the same, just similar. Here is assert, and there is while.
UPDATE2: I was wrong, this is not an issue with the validator, I was just trying to add a node without parentheses.
@AryazE I had a similar issue. However, the LibCST validator is working correctly here by preventing me from generating incorrect code.
I fixed my code and might help you if you share what are you trying to do. I guess you did the same mistake by adding a new node without parentheses. LibCST does not automatically add whitespace or parentheses for you.
Here is what I did: just copied the parentheses from the node I was trying to replace:
I have to transform (using a libcst.CSTTransformer) some 3rd party code, which might contain statements like
assert("foo") == "foo"
.Although this is a valid python code, I get the error
libcst._nodes.base.CSTValidationError: Must have at least one space after 'assert'.
I cannot fix this in the
leave_Assert
hook, as it is called after validation, and I cannot fix it in thevisit_Assert
hook, as the objectnode
is frozen.Currently, the only option I can think of is to do a regex search and replace before LibCST to add the missing whitespace and then feed it to my transformer.
Is there any easier way to do this, preferably within LibCST?
The text was updated successfully, but these errors were encountered: