Skip to content

Commit 43593a4

Browse files
committed
Markdown: add fake base class to Pattern to fix overrides
Currently `InlineProcessor` and every subclass of it violates the `override` rule as per Liskov Substitution Principle. Signature of "handleMatch" incompatible with supertype "Pattern" [override] Superclass: def handleMatch(self, m: Match[str]) -> Element | str Subclass: def handleMatch(self, m: Match[str], data: str) -> tuple[Element | str | None, int | None, int | None] For all *usage* purposes these aren't actual subclasses to one another, they're handled totally separately inside `__applyPattern`. However yes, this change totally disagrees with actual `isinstance` checks at run time (though even that is still for the best).
1 parent 3a56e00 commit 43593a4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

stubs/Markdown/markdown/inlinepatterns.pyi

+6-4
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,23 @@ class EmStrongItem(NamedTuple):
3939
builder: str
4040
tags: str
4141

42-
class Pattern:
42+
class _BasePattern:
4343
ANCESTOR_EXCLUDES: ClassVar[Collection[str]]
4444
pattern: str
4545
compiled_re: re.Pattern[str]
4646
md: Markdown
4747
def __init__(self, pattern: str, md: Markdown | None = None) -> None: ...
4848
def getCompiledRegExp(self) -> re.Pattern[str]: ...
49-
def handleMatch(self, m: re.Match[str]) -> str | Element | None: ...
5049
def type(self) -> str: ...
5150
def unescape(self, text: str) -> str: ...
5251

53-
class InlineProcessor(Pattern):
52+
class Pattern(_BasePattern):
53+
def handleMatch(self, m: re.Match[str]) -> str | Element | None: ...
54+
55+
class InlineProcessor(_BasePattern):
5456
safe_mode: bool
5557
def __init__(self, pattern: str, md: Markdown | None = None) -> None: ...
56-
def handleMatch(self, m: re.Match[str], data) -> tuple[Element, int, int] | tuple[None, None, None]: ... # type: ignore[override]
58+
def handleMatch(self, m: re.Match[str], data: str) -> tuple[Element, int, int] | tuple[None, None, None]: ...
5759

5860
class SimpleTextPattern(Pattern): ...
5961
class SimpleTextInlineProcessor(InlineProcessor): ...

0 commit comments

Comments
 (0)