Skip to content

Conversation

@brakhane
Copy link
Contributor

@brakhane brakhane commented Feb 5, 2022

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

This PR contains 2 changes:

  1. enum.Flag supports more than one bit to be set, and it is displayed like <Permission.READ|WRITE: 3>. The | character was not recognised by ReprHighlighter as part of a tag_name, causing only the first part to be highlighted.

  2. This is purely cosmetic, but I found the regexes to be really difficult to parse because of all the backslashes. Most of those actually weren't necessary, the commit explains the details further. However, this commit is completely optional.

enum.Flag allows more than one bit to be set, and its repr will show
something like <Permission.READ|WRITE: 3>.

For this to display correctly, we need to add the pipe symbol to the
tag regex.
Special characters lose their special meaning in character sets, so
there's no need to escape them with a backslash. Furthermore,
some backslash escaped characters have no special meaning,
so the backslash can be removed as well.

"]" does normally close a set, except when it's the first character.
Similarly, "-" has no special meaning at the beginning or the end.
Therefore, the order in a few character sets had to be slightly
modified.

Just to be sure, the old and new versions of the regexp were confirmed
to be equivalent via re.compile with the re.DEBUG flag and comparing the
output.
@codecov-commenter
Copy link

codecov-commenter commented Feb 5, 2022

Codecov Report

Merging #1920 (099893e) into master (e839bfb) will decrease coverage by 0.01%.
The diff coverage is 99.02%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1920      +/-   ##
==========================================
- Coverage   99.82%   99.81%   -0.02%     
==========================================
  Files          71       71              
  Lines        6943     7033      +90     
==========================================
+ Hits         6931     7020      +89     
- Misses         12       13       +1     
Flag Coverage Δ
unittests 99.81% <99.02%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
rich/default_styles.py 100.00% <ø> (ø)
rich/highlighter.py 100.00% <ø> (ø)
rich/markdown.py 100.00% <ø> (ø)
rich/syntax.py 99.27% <97.72%> (-0.34%) ⬇️
rich/pretty.py 99.71% <98.88%> (-0.29%) ⬇️
rich/__main__.py 100.00% <100.00%> (ø)
rich/_inspect.py 100.00% <100.00%> (ø)
rich/color.py 100.00% <100.00%> (ø)
rich/console.py 100.00% <100.00%> (ø)
rich/measure.py 100.00% <100.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3be88c0...099893e. Read the comment docs.

@willmcgugan
Copy link
Member

THanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants