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
printing: Remove curly braces from subscripted variables in python() and pycode() #20806
printing: Remove curly braces from subscripted variables in python() and pycode() #20806
Conversation
✅ Hi, I am the SymPy bot (v161). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.10. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
Where should I put the tests for this? They require |
Either you check for it in the test, something like
so import antlr in the test and check if it is present, if not just return. Or you may put the test in https://github.com/sympy/sympy/blob/master/sympy/parsing/tests/test_latex.py (where the code above is borrowed from). |
sympy/printing/python.py
Outdated
newsymbolname = symbolname | ||
# Remove curly braces from subscripted variables | ||
if '{' in symbolname: | ||
newsymbolname = ''.join([s if s != '{' and s != '}' else '' for s in symbolname]) |
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.
What about newsymbolname = symbolname.replace('{', '').replace('}', '')
?
Woah, I haven't touched sympy for half a year! :) Would you mind taking over here? |
Sure, I can probably give it a go. Seems like it is just to sort out the test aspect (and possibly rewrite using replace). |
Couldn't figure out how to easily get your repo to my local computer so went for the "edit on GitHub"-approach. Not a brilliant idea in hindsight, but hopefully it will pass... |
Benchmark results from GitHub Actions Lower numbers are good, higher numbers are bad. A ratio less than 1 Significantly changed benchmark results (PR vs master) Significantly changed benchmark results (master vs previous release) Full benchmark results can be found as artifacts in GitHub Actions |
My approach to doing this is twofold. To check out a PR I have the following in
With that I can do Then if I want to make changes and push to the PR it's:
The username and branch name are taken from the header of the webpage in the PR on GitHub |
References to other Issues or PRs
Fixes #20762
Brief description of what is fixed or changed
Added handling for subscripted variables in
python
andpycode
. Subscripted variables only become an issue when using a parsed latex expression, since latex wraps them in curly braces.python
andpycode
were creating variable names with curly braces in them, resulting in syntax errors. Added a simple check and modification inpython
, but redefined inherited_print_Symbol
inpycode
'sPythonCodePrinter
.Other comments
Release Notes