Markdown: use I/O protocols (#7851)

This commit is contained in:
Sebastian Rittau
2022-05-17 15:00:59 +02:00
committed by GitHub
parent 81be86af6e
commit a05ee9740d

View File

@@ -1,6 +1,6 @@
from _typeshed import Self
from collections.abc import Callable, Mapping, Sequence
from typing import Any, BinaryIO, ClassVar, TextIO
from typing import Any, ClassVar, Protocol
from typing_extensions import Literal
from xml.etree.ElementTree import Element
@@ -8,6 +8,18 @@ from .blockparser import BlockParser
from .extensions import Extension
from .util import HtmlStash, Registry
# TODO: The following protocols can be replaced by their counterparts from
# codecs, once they have been propagated to all type checkers.
class _WritableStream(Protocol):
def write(self, __data: bytes) -> object: ...
def seek(self, __offset: int, __whence: int) -> object: ...
def close(self) -> object: ...
class _ReadableStream(Protocol):
def read(self, __size: int = ...) -> bytes: ...
def seek(self, __offset: int, __whence: int) -> object: ...
def close(self) -> object: ...
class Markdown:
preprocessors: Registry
inlinePatterns: Registry
@@ -37,10 +49,7 @@ class Markdown:
def is_block_level(self, tag: str) -> bool: ...
def convert(self, source: str) -> str: ...
def convertFile(
self,
input: str | TextIO | BinaryIO | None = ...,
output: str | TextIO | BinaryIO | None = ...,
encoding: str | None = ...,
self, input: str | _ReadableStream | None = ..., output: str | _WritableStream | None = ..., encoding: str | None = ...
) -> Markdown: ...
def markdown(
@@ -53,8 +62,8 @@ def markdown(
) -> str: ...
def markdownFromFile(
*,
input: str | TextIO | BinaryIO | None = ...,
output: str | TextIO | BinaryIO | None = ...,
input: str | _ReadableStream | None = ...,
output: str | _WritableStream | None = ...,
encoding: str | None = ...,
extensions: Sequence[str | Extension] | None = ...,
extension_configs: Mapping[str, Mapping[str, Any]] | None = ...,