Skip to content

Commit c22a0b8

Browse files
authored
deprecate: mdformat.codepoints.ASCII_WHITESPACE (#481)
1 parent 43c6370 commit c22a0b8

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

docs/users/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
This log documents all Python API or CLI breaking backwards incompatible changes.
44
Note that there is currently no guarantee for a stable Markdown formatting style across versions.
55

6+
## **unreleased**
7+
8+
- Deprecated
9+
- `mdformat.codepoints.ASCII_WHITESPACE`
10+
611
## 0.7.19
712

813
- Deprecated

src/mdformat/codepoints/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,27 @@
55
"ASCII_WHITESPACE",
66
)
77

8+
import warnings
9+
810
from mdformat.codepoints._unicode_punctuation import UNICODE_PUNCTUATION
911
from mdformat.codepoints._unicode_whitespace import UNICODE_WHITESPACE
1012

1113
ASCII_CTRL = frozenset(chr(i) for i in range(32))
12-
ASCII_WHITESPACE = frozenset({chr(9), chr(10), chr(11), chr(12), chr(13), chr(32)})
14+
15+
16+
def __getattr__(name: str) -> frozenset[str]:
17+
"""Attribute getter fallback.
18+
19+
Used during the deprecation period of `ASCII_WHITESPACE`.
20+
"""
21+
if name == "ASCII_WHITESPACE":
22+
warnings.warn(
23+
"ASCII_WHITESPACE is deprecated because CommonMark v0.30 no longer "
24+
"defines ASCII whitespace.",
25+
DeprecationWarning,
26+
stacklevel=2,
27+
)
28+
return frozenset({chr(9), chr(10), chr(11), chr(12), chr(13), chr(32)})
29+
raise AttributeError(
30+
f"module {__name__!r} has no attribute {name!r}"
31+
) # pragma: no cover

src/mdformat/renderer/_util.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ def longest_consecutive_sequence(seq: str, char: str) -> int:
6565

6666
def maybe_add_link_brackets(link: str) -> str:
6767
"""Surround URI with brackets if required by spec."""
68-
if not link or (
69-
codepoints.ASCII_CTRL | codepoints.ASCII_WHITESPACE | {"(", ")"}
70-
).intersection(link):
68+
if not link or (codepoints.ASCII_CTRL | {" ", "(", ")"}).intersection(link):
7169
return "<" + link + ">"
7270
return link
7371

tests/test_api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,8 @@ def test_mdrenderer_no_finalize(tmp_path):
141141
unfinalized = MDRenderer().render(tokens, {}, env, finalize=False)
142142
finalized = MDRenderer().render(tokens, {}, env)
143143
assert finalized == unfinalized + "\n\n[gl ref]: https://gitlab.com\n"
144+
145+
146+
def test_ascii_whitespace_deprecation():
147+
with pytest.warns(DeprecationWarning):
148+
mdformat.codepoints.ASCII_WHITESPACE

0 commit comments

Comments
 (0)