From 4827cbf51eabb4be60bedc66682ad02c6b82e0ce Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Fri, 3 Dec 2021 09:27:35 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20REFACTOR:=20Remove=20`Attr?= =?UTF-8?q?Dict`=20(#181)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is no longer used is core or mdit-py-plugins, instead standard dictionaries are used. --- markdown_it/common/entities.py | 7 +------ markdown_it/common/utils.py | 10 ---------- markdown_it/rules_block/list.py | 4 ++-- markdown_it/rules_inline/entity.py | 4 ++-- markdown_it/utils.py | 17 +---------------- setup.cfg | 2 +- 6 files changed, 7 insertions(+), 37 deletions(-) diff --git a/markdown_it/common/entities.py b/markdown_it/common/entities.py index c05e5751..6bb2d343 100644 --- a/markdown_it/common/entities.py +++ b/markdown_it/common/entities.py @@ -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()} diff --git a/markdown_it/common/utils.py b/markdown_it/common/utils.py index e2abc368..edc24ca5 100644 --- a/markdown_it/common/utils.py +++ b/markdown_it/common/utils.py @@ -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): diff --git a/markdown_it/rules_block/list.py b/markdown_it/rules_block/list.py index f5bff688..a5318c96 100644 --- a/markdown_it/rules_block/list.py +++ b/markdown_it/rules_block/list.py @@ -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 diff --git a/markdown_it/rules_inline/entity.py b/markdown_it/rules_inline/entity.py index 753baf27..8354e6c7 100644 --- a/markdown_it/rules_inline/entity.py +++ b/markdown_it/rules_inline/entity.py @@ -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) @@ -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)) diff --git a/markdown_it/utils.py b/markdown_it/utils.py index 605a39d3..5d1ce723 100644 --- a/markdown_it/utils.py +++ b/markdown_it/utils.py @@ -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): @@ -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 = [] diff --git a/setup.cfg b/setup.cfg index 04230826..2815e3eb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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