Skip to content

🔧 MAINTAIN: Don't allow None value for StateBase.src #73

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

Merged
merged 5 commits into from
Apr 30, 2021

Conversation

hukkin
Copy link
Contributor

@hukkin hukkin commented Nov 4, 2020

Javascript implementation doesn't handle null values for StateBase.src, so I think we shouldn't either.

Also, it seems the None handling isn't fully implemented in all StateBase subclasses. E.g. StateInline.__init__ will throw an exception when src is None (from the line self.posMax = len(self.src)) even though there is None handling in the __init__ function before that.

@chrisjsewell
Copy link
Member

when you say the javascript doesn't handle it, you do know that javascript handles indexing very differently to python?
As I explained here #50 (comment), does not raise IndexErrors when indexing None or and index that is out of bounds.

You should also look at #32, where this ordinal caching was introduced, and where we specifically introduced the catch of None to fix a bug: #32 (comment)

@hukkin
Copy link
Contributor Author

hukkin commented Nov 4, 2020

you do know that javascript handles indexing very differently to python?

Yeah, I'm no JS expert 😄, but hopefully do know some basics.

does not raise IndexErrors when indexing None or and index that is out of bounds.

Out of bounds will not raise for sure, but I'm pretty sure indexing null does, no?

For instance this line https://github.com/markdown-it/markdown-it/blob/1b204ef54063aa7fde055f0e801e234be0a74d1e/lib/rules_inline/state_inline.js#L20 in the JS implementation will surely raise if src is null (accessing length atribute of null).

What would be the use case for initializing a State with src = None, and if there is one, could that perhaps be replaced by src = ""?

If None support needs to be kept then I think the type annotations should probably be changed to reflect that, and at least this line needs to be able to handle a None.

@hukkin
Copy link
Contributor Author

hukkin commented Nov 4, 2020

I found the MyST-NB usage of StateCore(None, .... All tests seem to pass also when instantiating with an empty string: executablebooks/MyST-NB#277 so it seems at least that particular use doesn't have a hard requirement for src = None.

@codecov
Copy link

codecov bot commented Nov 12, 2020

Codecov Report

Merging #73 (bce699c) into master (c55a243) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #73   +/-   ##
=======================================
  Coverage   96.10%   96.10%           
=======================================
  Files          60       60           
  Lines        3232     3234    +2     
=======================================
+ Hits         3106     3108    +2     
  Misses        126      126           
Flag Coverage Δ
pytests 96.10% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
markdown_it/ruler.py 89.65% <100.00%> (+0.18%) ⬆️

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 c55a243...bce699c. Read the comment docs.

@hukkin hukkin changed the title Dont allow None value for StateBase.src 🔧 MAINTAIN: Dont allow None value for StateBase.src Dec 13, 2020
@hukkin hukkin force-pushed the src-none branch 2 times, most recently from db7ade3 to 1d63db5 Compare December 29, 2020 21:27
@hukkin
Copy link
Contributor Author

hukkin commented Apr 23, 2021

I think this should be a pretty safe merge now that myst-nb has seen a few releases after the usage of StateBase.src = None was removed there, and jupyter book release also uses a myst-nb version that doesn't set the None. What do you think @chrisjsewell ?

@chrisjsewell chrisjsewell changed the title 🔧 MAINTAIN: Dont allow None value for StateBase.src 🔧 MAINTAIN: Don't allow None value for StateBase.src Apr 30, 2021
@chrisjsewell chrisjsewell merged commit 99ebfac into executablebooks:master Apr 30, 2021
@hukkin hukkin deleted the src-none branch April 30, 2021 22:50
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