Update StringVar to match Python str behavior (#5417)#6596
Conversation
Add missing `lstrip` and `rstrip` methods to align with Python's `str` interface. Update `strip` method to accept a `chars` argument, consistent with `str.strip`.
Greptile SummaryThis PR adds
Confidence Score: 5/5Safe to merge — the change is additive, the JS helpers are correct for well-formed strings, and existing behaviour of the no-arg strip path is preserved. All three strip variants correctly fall back to native trim* methods when no chars are supplied, and use a Set-based character lookup (not a regex) for the chars path. Surrogate-pair handling in the backward-scan of pyRstrip uses codePointAt(end-2), which correctly identifies two-code-unit code points for well-formed strings. The @var_operation decorator's LiteralVar.create(None) → null serialisation is confirmed by the updated unit tests. No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "Drop the NoneVar fast path; helpers hand..." | Re-trigger Greptile |
|
I think the greptile raises some valid points. |
Hey @FarhanAliRaza, I agree. The escaping issue should be a straightforward fix. I’m working on a solution for the first point. New to the codebase, so still exploring. |
Merging this PR will not alter performance
Comparing Footnotes
|
…rals Constructing JS regex character classes from Python values was broken: quoted literal serialization leaked into the class, var expressions were embedded verbatim into static regex syntax, and regex-special characters (], \, ^, -) were not escaped. Replace with pyStrip/pyLstrip/pyRstrip helpers in state.js that match Python str semantics (code-point aware, null chars strips whitespace), and detect the no-args case with isinstance(chars, NoneVar) rather than comparing against the string "null". Add end-to-end integration tests covering whitespace and chars-set stripping, including regex-special characters and state var chars. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
pyStrip/pyLstrip/pyRstrip already fall back to trim/trimStart/trimEnd when chars is null, so always emit the helper call. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add missing
lstripandrstripmethods to align with Python'sstrinterface. Updatestripmethod to accept acharsargument, consistent withstr.strip. Closes #5417.All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission:
Changes To Core Features: