Skip to content

Commit

Permalink
Fix typing import
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval authored Dec 31, 2024
1 parent b11cbdb commit c4e9769
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions nbconvert/filters/markdown_mistune.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import mimetypes
import os
from html import escape
from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, Match, Optional, Tuple
from typing import TYPE_CHECKING, Any, ClassVar, Dict, Iterable, Match, Optional, Protocol, Tuple

import bs4
from pygments import highlight
Expand All @@ -20,6 +20,16 @@

from nbconvert.filters.strings import add_anchor


if TYPE_CHECKING:
try:
from mistune.plugins import Plugin
except ImportError:

class Plugin(Protocol):
def __call__(self, markdown: "Markdown") -> None: ...


try: # for Mistune >= 3.0
from mistune import ( # type:ignore[attr-defined]
BlockParser,
Expand Down Expand Up @@ -48,20 +58,11 @@
MISTUNE_V3 = False
MISTUNE_V3_ATX = False

def import_plugin(name: str) -> "MarkdownPlugin": # type: ignore[misc]
def import_plugin(name: str) -> "Plugin": # type: ignore[misc]
"""Simple implementation of Mistune V3's import_plugin for V2."""
return PLUGINS[name] # type: ignore[no-any-return]


if TYPE_CHECKING:
try:
from mistune.plugins import Plugin
except ImportError:

class Plugin(Protocol):
def __call__(self, markdown: "Markdown") -> None: ...


class InvalidNotebook(Exception):
"""An invalid notebook model."""

Expand Down

0 comments on commit c4e9769

Please sign in to comment.