Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃憣 IMPROVE: Ensure len(state.src) == len(state.srcCharCode) #108

Merged
merged 11 commits into from Dec 29, 2020

Conversation

geebos
Copy link
Contributor

@geebos geebos commented Dec 25, 2020

def normalize(state: StateCore) -> None:

    # Normalize newlines
    string = NEWLINES_RE.sub("\n", state.src)

    # Replace NULL characters
    string = NULL_RE.sub("\uFFFD", string)

    state.src = string

When updating state.src, state.srcCharCode should be updated synchronously.

@welcome
Copy link

welcome bot commented Dec 25, 2020

Thanks for submitting your first pull request! You are awesome! 馃

If you haven't done so already, check out EBP's Code of Conduct and our Contributing Guide, as this will greatly help the review process.

Welcome to the EBP community! 馃帀

@codecov
Copy link

codecov bot commented Dec 25, 2020

Codecov Report

Merging #108 (4de72a8) into master (2136ab7) will decrease coverage by 0.02%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #108      +/-   ##
==========================================
- Coverage   96.49%   96.46%   -0.03%     
==========================================
  Files          69       69              
  Lines        2912     2916       +4     
==========================================
+ Hits         2810     2813       +3     
- Misses        102      103       +1     
Flag Coverage 螖
pytests 96.46% <87.50%> (-0.03%) 猬囷笍

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

Impacted Files Coverage 螖
markdown_it/rules_core/state_core.py 100.00% <酶> (酶)
markdown_it/rules_inline/state_inline.py 98.87% <酶> (-0.02%) 猬囷笍
markdown_it/ruler.py 83.92% <83.33%> (-0.04%) 猬囷笍
markdown_it/rules_block/state_block.py 98.54% <100.00%> (酶)

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 2136ab7...1b8905d. Read the comment docs.

Copy link
Member

@hukkin hukkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I made suggestions that use the @property decorator to keep API identical to JS markdown-it.

With those changes I believe we can also remove line 10 from the __init__ that sets self.srcCharCode.

@hukkin
Copy link
Member

hukkin commented Dec 25, 2020

Also, might make sense to add the @property to StateBase base class only, to get identical behavior in all StateBase subclasses.

geebos and others added 3 commits December 25, 2020 22:29
Co-authored-by: Taneli Hukkinen <hukkinj1@users.noreply.github.com>
Co-authored-by: Taneli Hukkinen <hukkinj1@users.noreply.github.com>
@geebos
Copy link
Contributor Author

geebos commented Dec 25, 2020

Also, might make sense to add the @property to StateBase base class only, to get identical behavior in all StateBase subclasses.

Nice suggestions! I have added the @property to StateBase. In addition, I have added srcCharCode to @property to avoid assigning srcCharCode from outer codes.

Copy link
Member

@hukkin hukkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to remove the line

self.srcCharCode = [ord(c) for c in src] if src is not None else []

in StateInline.__init__.

In StateBlock.__init__ we can make the lines

        self.src = src
        if srcCharCode is not None:
            self.srcCharCode = srcCharCode
        else:
            self.srcCharCode = [ord(c) for c in src] if src is not None else []

something like

        if srcCharCode is not None:
            self._src = src
            self.srcCharCode = srcCharCode
        else:
            self.src = src

This will keep the (presumably) performance improvement in place.

markdown_it/ruler.py Outdated Show resolved Hide resolved
@hukkin
Copy link
Member

hukkin commented Dec 26, 2020

Looking good @geebos ! Did you see this comment #108 (review) . You think those two changes can be used here too?

@geebos
Copy link
Contributor Author

geebos commented Dec 26, 2020

Looking good @geebos ! Did you see this comment #108 (review) . You think those two changes can be used here too?

Thanks for reminding. I have added a set_underline_src method in StateBase, because we cant set _src directly in StateBlock.

@hukkin
Copy link
Member

hukkin commented Dec 26, 2020

we cant set _src directly in StateBlock.

What makes you think so? I believe this should work just fine as long as there's only one preceding underscore (_src), not two (__src). In case it's mypy that's giving you trouble, you can type annotate self._src in StateBase after the class declaration like

class StateBase:
    _src: str

@geebos
Copy link
Contributor Author

geebos commented Dec 26, 2020

You are right. I confuse them.

@hukkin
Copy link
Member

hukkin commented Dec 26, 2020

Nice, this looks very good to me!

@chrisjsewell
Copy link
Member

thanks!

@chrisjsewell chrisjsewell changed the title fix:ensure len(state.src) equals to len(state.srcCharCode) 馃憣 IMPROVE: Ensure len(state.src) == len(state.srcCharCode) Dec 29, 2020
@chrisjsewell chrisjsewell merged commit ef60702 into executablebooks:master Dec 29, 2020
@welcome
Copy link

welcome bot commented Dec 29, 2020

Congrats on your first merged pull request in this project! 馃帀
congrats

Thank you for contributing, we are very proud of you! 鉂わ笍

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.

None yet

3 participants