Skip to content

♻️ REFACTOR: Remove AttrDict #181

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 1 commit into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions markdown_it/common/entities.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
"""HTML5 entities map: { name -> characters }."""
import html.entities

from markdown_it.utils import AttrDict


DATA = {name.rstrip(";"): chars for name, chars in html.entities.html5.items()}

entities = AttrDict(DATA)
entities = {name.rstrip(";"): chars for name, chars in html.entities.html5.items()}
10 changes: 0 additions & 10 deletions markdown_it/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ def charCodeAt(src: str, pos: int) -> Any:
return None


# function _class(obj) { return Object.prototype.toString.call(obj); }


def isString(obj: object) -> bool:
return isinstance(obj, str)


has = hasattr


# Merge objects
#
def assign(obj):
Expand Down
4 changes: 2 additions & 2 deletions markdown_it/rules_block/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ def list_block(state: StateBlock, startLine: int, endLine: int, silent: bool):
while pos < maximum:
ch = state.srcCharCode[pos]

if ch == 0x09:
if ch == 0x09: # \t
offset += 4 - (offset + state.bsCount[nextLine]) % 4
elif ch == 0x20:
elif ch == 0x20: # \s
offset += 1
else:
break
Expand Down
4 changes: 2 additions & 2 deletions markdown_it/rules_inline/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re

from ..common.entities import entities
from ..common.utils import has, isValidEntityCode, fromCodePoint
from ..common.utils import isValidEntityCode, fromCodePoint
from .state_inline import StateInline

DIGITAL_RE = re.compile(r"^&#((?:x[a-f0-9]{1,6}|[0-9]{1,7}));", re.IGNORECASE)
Expand Down Expand Up @@ -42,7 +42,7 @@ def entity(state: StateInline, silent: bool):
else:
match = NAMED_RE.search(state.src[pos:])
if match:
if has(entities, match.group(1)):
if match.group(1) in entities:
if not silent:
state.pending += entities[match.group(1)]
state.pos += len(match.group(0))
Expand Down
17 changes: 1 addition & 16 deletions markdown_it/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Union
from typing import Callable, List, Optional, Union


class OptionsDict(dict):
Expand Down Expand Up @@ -87,21 +87,6 @@ def highlight(self, value: Optional[Callable[[str, str, str], str]]):
self["highlight"] = value


if TYPE_CHECKING:
AttrDict = Any
else:

class AttrDict(dict):
def __init__(self, *args, **kwargs):
super(AttrDict, self).__init__(*args, **kwargs)
self.__dict__ = self

# recursively apply to all nested dictionaries
for key, item in list(self.items()):
if isinstance(item, dict):
self[key] = AttrDict(item)


def read_fixture_file(path: Union[str, Path]) -> List[list]:
text = Path(path).read_text(encoding="utf-8")
tests = []
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ project_urls =
[options]
packages = find:
install_requires =
mdurl
attrs>=19,<22
mdurl~=0.1
typing_extensions>=3.7.4;python_version<'3.8'
python_requires = ~=3.6
include_package_data = True
Expand Down