Skip to content

Commit 9f5c3ca

Browse files
authored
Finish typing the Blocks interface and type additional referenced files (#2652)
* Finish typing the Blocks interface and type additional referenced files
1 parent 84a087b commit 9f5c3ca

File tree

8 files changed

+120
-86
lines changed

8 files changed

+120
-86
lines changed

.pyspelling.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ matrix:
131131
context_visible_first: true
132132
delimiters:
133133
# Ignore lint (noqa) and coverage (pragma) as well as shebang (#!)
134-
- open: '^(?: *(?:noqa\b|pragma: no cover)|!)'
134+
- open: '^(?: *(?:noqa\b|pragma: no cover|type: .*?)|!)'
135135
close: '$'
136136
# Ignore Python encoding string -*- encoding stuff -*-
137137
- open: '^ *-\*-'

docs/src/markdown/about/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- **NEW**: SuperFences: Add `relaxed_headers` option which can tolerate bad content in the fenced code header. When
66
enabled, code blocks with bad content in the header will likely still convert into code blocks, often respecting
77
the specified language.
8+
- **NEW**: Add type hints to the Blocks interface and a few additional files.
89
- **FIX**: Blocks: Fix some corner cases of nested blocks with lists.
910
- **FIX**: Tab and Tabbed: Fix a case where tabs could fail if `combine_header_slug` was enabled and there was no
1011
header.

pymdownx/__meta__.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Meta related things."""
2+
from __future__ import annotations
23
from collections import namedtuple
34
import re
45

@@ -69,17 +70,21 @@ class Version(namedtuple("Version", ["major", "minor", "micro", "release", "pre"
6970
Version(1, 0, 0, "final") 1.0
7071
Version(1, 2, 0, "final") 1.2
7172
Version(1, 2, 3, "final") 1.2.3
72-
Version(1, 2, 0, ".dev-alpha", pre=4) 1.2a4
73-
Version(1, 2, 0, ".dev-beta", pre=4) 1.2b4
74-
Version(1, 2, 0, ".dev-candidate", pre=4) 1.2rc4
73+
Version(1, 2, 0, "alpha", pre=4) 1.2a4
74+
Version(1, 2, 0, "beta", pre=4) 1.2b4
75+
Version(1, 2, 0, "candidate", pre=4) 1.2rc4
7576
Version(1, 2, 0, "final", post=1) 1.2.post1
7677
Version(1, 2, 3, ".dev") 1.2.3.dev0
7778
Version(1, 2, 3, ".dev", dev=1) 1.2.3.dev1
7879
```
7980
8081
"""
8182

82-
def __new__(cls, major, minor, micro, release="final", pre=0, post=0, dev=0):
83+
def __new__(
84+
cls,
85+
major: int, minor: int, micro: int, release: str = "final",
86+
pre: int = 0, post: int = 0, dev: int = 0
87+
) -> Version:
8388
"""Validate version info."""
8489

8590
# Ensure all parts are positive integers.
@@ -115,31 +120,31 @@ def __new__(cls, major, minor, micro, release="final", pre=0, post=0, dev=0):
115120

116121
return super().__new__(cls, major, minor, micro, release, pre, post, dev)
117122

118-
def _is_pre(self):
123+
def _is_pre(self) -> bool:
119124
"""Is prerelease."""
120125

121-
return self.pre > 0
126+
return bool(self.pre > 0)
122127

123-
def _is_dev(self):
128+
def _is_dev(self) -> bool:
124129
"""Is development."""
125130

126131
return bool(self.release < "alpha")
127132

128-
def _is_post(self):
133+
def _is_post(self) -> bool:
129134
"""Is post."""
130135

131-
return self.post > 0
136+
return bool(self.post > 0)
132137

133-
def _get_dev_status(self): # pragma: no cover
138+
def _get_dev_status(self) -> str: # pragma: no cover
134139
"""Get development status string."""
135140

136141
return DEV_STATUS[self.release]
137142

138-
def _get_canonical(self):
143+
def _get_canonical(self) -> str:
139144
"""Get the canonical output string."""
140145

141146
# Assemble major, minor, micro version and append `pre`, `post`, or `dev` if needed..
142-
if self.micro == 0:
147+
if self.micro == 0 and self.major != 0:
143148
ver = f"{self.major}.{self.minor}"
144149
else:
145150
ver = f"{self.major}.{self.minor}.{self.micro}"
@@ -153,11 +158,14 @@ def _get_canonical(self):
153158
return ver
154159

155160

156-
def parse_version(ver, pre=False):
161+
def parse_version(ver: str) -> Version:
157162
"""Parse version into a comparable Version tuple."""
158163

159164
m = RE_VER.match(ver)
160165

166+
if m is None:
167+
raise ValueError(f"'{ver}' is not a valid version")
168+
161169
# Handle major, minor, micro
162170
major = int(m.group('major'))
163171
minor = int(m.group('minor')) if m.group('minor') else 0
@@ -185,5 +193,5 @@ def parse_version(ver, pre=False):
185193
return Version(major, minor, micro, release, pre, post, dev)
186194

187195

188-
__version_info__ = Version(10, 14, 3, "final")
196+
__version_info__ = Version(10, 15, 0, "final")
189197
__version__ = __version_info__._get_canonical()

0 commit comments

Comments
 (0)