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

Conversation

andersk
Copy link
Contributor

@andersk andersk commented Nov 13, 2023

No description provided.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@@ -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.

@@ -21,7 +21,7 @@ class _ReadableStream(Protocol):

class Markdown:
preprocessors: Registry[preprocessors.Preprocessor]
inlinePatterns: Registry[inlinepatterns.InlineProcessor]
inlinePatterns: Registry[inlinepatterns.Pattern]
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.

@@ -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.

@oprypin
Copy link
Contributor

oprypin commented Nov 14, 2023

Related pull request:

I'll need to update my pull request after this one is merged.

I'd say let's merge this one first.

@AlexWaygood AlexWaygood merged commit 643d911 into python:main Nov 14, 2023
@andersk andersk deleted the inlinePatterns branch November 15, 2023 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants