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: Make Token.attrs a List[Tuple[str, Any]] #102

Closed
wants to merge 6 commits into from

Conversation

hukkin
Copy link
Member

@hukkin hukkin commented Dec 19, 2020

No description provided.

@codecov
Copy link

codecov bot commented Dec 19, 2020

Codecov Report

Merging #102 (1c27822) into master (00a28a6) will increase coverage by 0.12%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #102      +/-   ##
==========================================
+ Coverage   96.38%   96.50%   +0.12%     
==========================================
  Files          72       72              
  Lines        3205     3202       -3     
==========================================
+ Hits         3089     3090       +1     
+ Misses        116      112       -4     
Flag Coverage 螖
pytests 96.50% <100.00%> (+0.12%) 猬嗭笍

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

Impacted Files Coverage 螖
markdown_it/renderer.py 100.00% <100.00%> (+1.80%) 猬嗭笍
markdown_it/rules_block/list.py 98.84% <100.00%> (酶)
markdown_it/rules_block/table.py 100.00% <100.00%> (酶)
markdown_it/rules_core/linkify.py 98.87% <100.00%> (酶)
markdown_it/rules_inline/autolink.py 96.22% <100.00%> (酶)
markdown_it/rules_inline/image.py 98.86% <100.00%> (酶)
markdown_it/rules_inline/link.py 98.83% <100.00%> (酶)
markdown_it/token.py 94.31% <100.00%> (+2.36%) 猬嗭笍
markdown_it/tree.py 92.98% <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 00a28a6...1c27822. Read the comment docs.

@hukkin
Copy link
Member Author

hukkin commented Dec 19, 2020

These changes do not break compatibility with mdit-py-plugins, but tests will need to be updated there.

@hukkin
Copy link
Member Author

hukkin commented Dec 19, 2020

executablebooks/mdit-py-plugins#6 will fix mdit-py-plugins tests if this is merged.

if i < 0:
tmpAttrs.append(["class", options.langPrefix + langName])
else:
tmpAttrs[i][1] += " " + options.langPrefix + langName
Copy link
Member Author

Choose a reason for hiding this comment

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

This line actually seems to have a bug that we're fixing by using the immutable tuple 馃槃 Mutating tmpAttrs[i] here will also mutate token.attrs[i] because tmpAttrs is a copy, not a deep copy, of token.attrs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Here's the fix in JS markdown-it markdown-it/markdown-it@c9949dd

If we don't end up merging this PR, we should do the same change.

Copy link
Member Author

Choose a reason for hiding this comment

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

This fix is now in merged in master of markdown-it-py btw

@hukkin
Copy link
Member Author

hukkin commented Jan 13, 2021

In fact, if we want to make Token.attrs even better, we could use a Dict[str, Any] as the underlying structure. Why markdown-it doesn't use an object is exlained here markdown-it/markdown-it#142 (comment) :

Because ordering makes sence for testing, and no needs to care about hacks like "proto" name and so on.

A Python 3.6 OrderedDict or Python 3.7+ dict doesn't suffer from any of the issues why the custom list structure was used for a mapping. Using a dict would likely result in a small performance increase.

@chrisjsewell
Copy link
Member

Superseded by #144

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