-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[highlighter] Add complex numbers pattern to our highlighter's number
matching
#2219
[highlighter] Add complex numbers pattern to our highlighter's number
matching
#2219
Conversation
0d0e621
to
dda6ce5
Compare
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.
I don't think this will work with negative imaginary numbers, e.g. "1-3j"
dda6ce5
to
f67f426
Compare
Meh, silly me 😓 - as I've never used these numbers myself I naively assumed that they were always an imaginary part added to the real one, but of course it can also be a subtraction! Fixed in f67f426 Also... While I was there I checked Wikipedia once again, and I found this:
But it seems that in Python this |
No worries. We only really need to worry about what the repr for complex numbers can produce. I'm afraid it does get more complex. If the imaginary part has an exponent, the regex fails. e.g. I suspect that will occur almost never, but maybe we should try to support it. I'm actually thinking that maybe the best approach would be to add a new regex for a new number type, which includes the parenthesis. So it matches |
I'm trying to implement this, but without any success so far... I have a regex that works in isolation in regex101 with several test cases of complex numbers, but once I mix it with the other ones we already have in the highlighter it breaks quite a lot of other test cases 😬 |
I made some progress, but still not there for the moment... 😅 |
@willmcgugan I think I got there! It seems that I cannot prevent the "braces" to take precedence (even if I move the new Here with a different visual style than "plain" numbers, just to illustrate that the matching is well and truly different: What do you think? Good enough, or should we try harder to include the braces into this representation? 🙂 |
…n one, rather than being part of the `number` one
22be33e
to
5e67e22
Compare
Codecov Report
@@ Coverage Diff @@
## master #2219 +/- ##
==========================================
- Coverage 99.07% 98.89% -0.18%
==========================================
Files 72 73 +1
Lines 7555 7625 +70
==========================================
+ Hits 7485 7541 +56
- Misses 70 84 +14
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Nice work. If the braces aren't technically part of the number then it makes sense to leave them out of the regex. Not sure about the styling. @flaport do you have any particular preference re styling? Would you expect it to look different from a non-complex number? |
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.
Would you mind adding an entry in CHANGELOG.md with a link to the issue
Sure! Done in 9ae04d2 🙂 |
Type of changes
Checklist
Description
closes #2214
The fix in action:
In IPython:
In a Jupyter notebook:
In plain Python