Skip to content

markdown: Accept legacy Pattern in inlinePatterns registry #11027

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
Nov 14, 2023
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
2 changes: 1 addition & 1 deletion stubs/Markdown/markdown/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class _ReadableStream(Protocol):

class Markdown:
preprocessors: Registry[preprocessors.Preprocessor]
inlinePatterns: Registry[inlinepatterns.InlineProcessor]
inlinePatterns: Registry[inlinepatterns.Pattern]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is my mistake, actually this PR is more correct 👍

I was adding this both upstream and in typeshed btw.

treeprocessors: Registry[treeprocessors.Treeprocessor]
postprocessors: Registry[postprocessors.Postprocessor]
parser: blockparser.BlockParser
Expand Down
2 changes: 1 addition & 1 deletion stubs/Markdown/markdown/extensions/smarty.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ class SmartyExtension(Extension):
def educateEllipses(self, md: Markdown) -> None: ...
def educateAngledQuotes(self, md: Markdown) -> None: ...
def educateQuotes(self, md: Markdown) -> None: ...
inlinePatterns: util.Registry[inlinepatterns.InlineProcessor]
inlinePatterns: util.Registry[inlinepatterns.Pattern]

def makeExtension(**kwargs) -> SmartyExtension: ...
2 changes: 1 addition & 1 deletion stubs/Markdown/markdown/inlinepatterns.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from xml.etree.ElementTree import Element
from markdown import util
from markdown.core import Markdown

def build_inlinepatterns(md: Markdown, **kwargs) -> util.Registry[InlineProcessor]: ...
def build_inlinepatterns(md: Markdown, **kwargs) -> util.Registry[Pattern]: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InlineProcessor is a subclass of Pattern and everywhere else the more general class is correct. However this particular method really does create a registry of only InlineProcessor. If the covariance stuff all works out, I believe we should leave this part as is. I'll try later today what mypy thinks about it with the full codebase

Suggested change
def build_inlinepatterns(md: Markdown, **kwargs) -> util.Registry[Pattern]: ...
def build_inlinepatterns(md: Markdown, **kwargs) -> util.Registry[InlineProcessor]: ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Registry can’t be covariant because it’s mutable. That is, we can’t convert reg1: Registry[InlineProcessor] to reg2: Registry[Pattern] because then one could add a Pattern to reg2 and read it out from reg1 as an InlineProcessor even if it isn’t.

So if this is going to be used as Registry[Pattern], it needs to be declared that way from the start.


NOIMG: str
BACKTICK_RE: str
Expand Down