Skip to content

Implement JS-esque StateBase.srcCharCodeAt#190

Open
hukkin wants to merge 6 commits intoexecutablebooks:masterfrom
hukkin:charcodeat
Open

Implement JS-esque StateBase.srcCharCodeAt#190
hukkin wants to merge 6 commits intoexecutablebooks:masterfrom
hukkin:charcodeat

Conversation

@hukkin
Copy link
Copy Markdown
Contributor

@hukkin hukkin commented Jan 24, 2022

Replaces use of StateBase.srcCharCode with the more JS-esque StateBase.srcCharCodeAt that can return None.

I didn't remove StateBase.srcCharCode for ease of migration because mdit-py-plugins use it. But did deprecate it.

Happy to hear what you think @chrisjsewell . Not sure if this is the solution or migration strategy you want, but it's something 😄

I haven't measured performance yet. We may want to do that if this is something we want to proceed with otherwise

EDIT: This PR is in response to discussion in #186

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 24, 2022

Codecov Report

❌ Patch coverage is 97.89474% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.11%. Comparing base (d6adf66) to head (6323f8b).
⚠️ Report is 104 commits behind head on master.

Files with missing lines Patch % Lines
markdown_it/ruler.py 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #190      +/-   ##
==========================================
- Coverage   96.17%   96.11%   -0.07%     
==========================================
  Files          61       61              
  Lines        3267     3267              
==========================================
- Hits         3142     3140       -2     
- Misses        125      127       +2     
Flag Coverage Δ
pytests 96.11% <97.89%> (-0.07%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hukkin
Copy link
Copy Markdown
Contributor Author

hukkin commented Jan 25, 2022

Seeing that this PR only removes 4 instances of try: ... except IndexError: handling and that almost always we do an if pos < maximum: check or similar to ensure None is not an option, I actually still think it may be a fine decision to reject this change, and simply be more strict/explicit about out-of-range indices than upstream is. The current state is also better for performance. Arguably we'd be throwing away some work that has gone into making upstream more type safe.

The downsides for rejecting are diverging slightly from upstream logic, and the chance that there's still some place in the code where None handling is required but we don't know.

@hukkin hukkin mentioned this pull request Feb 10, 2022
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.

1 participant