mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-22 03:41:28 +08:00
Python 3 stubs: use str instead of typing.Text (#7638)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from _typeshed import Self
|
||||
from collections.abc import Callable, Mapping, Sequence
|
||||
from typing import Any, BinaryIO, ClassVar, Text, TextIO
|
||||
from typing import Any, BinaryIO, ClassVar, TextIO
|
||||
from typing_extensions import Literal
|
||||
from xml.etree.ElementTree import Element
|
||||
|
||||
@@ -15,9 +15,9 @@ class Markdown:
|
||||
postprocessors: Registry
|
||||
parser: BlockParser
|
||||
htmlStash: HtmlStash
|
||||
output_formats: ClassVar[dict[Literal["xhtml", "html"], Callable[[Element], Text]]]
|
||||
output_formats: ClassVar[dict[Literal["xhtml", "html"], Callable[[Element], str]]]
|
||||
output_format: Literal["xhtml", "html"]
|
||||
serializer: Callable[[Element], Text]
|
||||
serializer: Callable[[Element], str]
|
||||
tab_length: int
|
||||
block_level_elements: list[str]
|
||||
def __init__(
|
||||
@@ -30,12 +30,12 @@ class Markdown:
|
||||
) -> None: ...
|
||||
def build_parser(self) -> Markdown: ...
|
||||
def registerExtensions(self, extensions: Sequence[Extension | str], configs: Mapping[str, Mapping[str, Any]]) -> Markdown: ...
|
||||
def build_extension(self, ext_name: Text, configs: Mapping[str, str]) -> Extension: ...
|
||||
def build_extension(self, ext_name: str, configs: Mapping[str, str]) -> Extension: ...
|
||||
def registerExtension(self, extension: Extension) -> Markdown: ...
|
||||
def reset(self: Self) -> Self: ...
|
||||
def set_output_format(self, format: Literal["xhtml", "html"]) -> Markdown: ...
|
||||
def is_block_level(self, tag: str) -> bool: ...
|
||||
def convert(self, source: Text) -> Text: ...
|
||||
def convert(self, source: str) -> str: ...
|
||||
def convertFile(
|
||||
self,
|
||||
input: str | TextIO | BinaryIO | None = ...,
|
||||
@@ -44,13 +44,13 @@ class Markdown:
|
||||
) -> Markdown: ...
|
||||
|
||||
def markdown(
|
||||
text: Text,
|
||||
text: str,
|
||||
*,
|
||||
extensions: Sequence[str | Extension] | None = ...,
|
||||
extension_configs: Mapping[str, Mapping[str, Any]] | None = ...,
|
||||
output_format: Literal["xhtml", "html"] | None = ...,
|
||||
tab_length: int | None = ...,
|
||||
) -> Text: ...
|
||||
) -> str: ...
|
||||
def markdownFromFile(
|
||||
*,
|
||||
input: str | TextIO | BinaryIO | None = ...,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
from _typeshed import Self
|
||||
from collections.abc import Iterable, Iterator
|
||||
from typing import Any, Text
|
||||
from typing import Any
|
||||
|
||||
from .connections import Connection
|
||||
|
||||
class Cursor:
|
||||
connection: Connection[Any]
|
||||
description: tuple[Text, ...]
|
||||
description: tuple[str, ...]
|
||||
rownumber: int
|
||||
rowcount: int
|
||||
arraysize: int
|
||||
@@ -19,11 +19,11 @@ class Cursor:
|
||||
def setinputsizes(self, *args) -> None: ...
|
||||
def setoutputsizes(self, *args) -> None: ...
|
||||
def nextset(self) -> bool | None: ...
|
||||
def mogrify(self, query: Text, args: object = ...) -> str: ...
|
||||
def execute(self, query: Text, args: object = ...) -> int: ...
|
||||
def executemany(self, query: Text, args: Iterable[object]) -> int | None: ...
|
||||
def callproc(self, procname: Text, args: Iterable[Any] = ...) -> Any: ...
|
||||
def scroll(self, value: int, mode: Text = ...) -> None: ...
|
||||
def mogrify(self, query: str, args: object = ...) -> str: ...
|
||||
def execute(self, query: str, args: object = ...) -> int: ...
|
||||
def executemany(self, query: str, args: Iterable[object]) -> int | None: ...
|
||||
def callproc(self, procname: str, args: Iterable[Any] = ...) -> Any: ...
|
||||
def scroll(self, value: int, mode: str = ...) -> None: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *exc_info: object) -> None: ...
|
||||
# Methods returning result tuples are below.
|
||||
@@ -34,17 +34,17 @@ class Cursor:
|
||||
|
||||
class DictCursorMixin:
|
||||
dict_type: Any # TODO: add support if someone needs this
|
||||
def fetchone(self) -> dict[Text, Any] | None: ...
|
||||
def fetchmany(self, size: int | None = ...) -> tuple[dict[Text, Any], ...]: ...
|
||||
def fetchall(self) -> tuple[dict[Text, Any], ...]: ...
|
||||
def __iter__(self) -> Iterator[dict[Text, Any]]: ...
|
||||
def fetchone(self) -> dict[str, Any] | None: ...
|
||||
def fetchmany(self, size: int | None = ...) -> tuple[dict[str, Any], ...]: ...
|
||||
def fetchall(self) -> tuple[dict[str, Any], ...]: ...
|
||||
def __iter__(self) -> Iterator[dict[str, Any]]: ...
|
||||
|
||||
class SSCursor(Cursor):
|
||||
def fetchall(self) -> list[tuple[Any, ...]]: ... # type: ignore[override]
|
||||
def fetchall_unbuffered(self) -> Iterator[tuple[Any, ...]]: ...
|
||||
def scroll(self, value: int, mode: Text = ...) -> None: ...
|
||||
def scroll(self, value: int, mode: str = ...) -> None: ...
|
||||
|
||||
class DictCursor(DictCursorMixin, Cursor): ... # type: ignore[misc]
|
||||
|
||||
class SSDictCursor(DictCursorMixin, SSCursor): # type: ignore[misc]
|
||||
def fetchall_unbuffered(self) -> Iterator[dict[Text, Any]]: ... # type: ignore[override]
|
||||
def fetchall_unbuffered(self) -> Iterator[dict[str, Any]]: ... # type: ignore[override]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import sys
|
||||
from collections.abc import Callable, Iterator
|
||||
from typing import Any, NamedTuple, Pattern, Text, TypeVar
|
||||
from typing import Any, NamedTuple, Pattern, TypeVar
|
||||
from typing_extensions import ParamSpec
|
||||
|
||||
_C = TypeVar("_C", bound=Callable[..., Any])
|
||||
@@ -34,42 +34,42 @@ DEF: Pattern[str]
|
||||
_dict = dict # conflicts with attribute name
|
||||
|
||||
class FunctionMaker:
|
||||
args: list[Text]
|
||||
varargs: Text | None
|
||||
varkw: Text | None
|
||||
args: list[str]
|
||||
varargs: str | None
|
||||
varkw: str | None
|
||||
defaults: tuple[Any, ...]
|
||||
kwonlyargs: list[Text]
|
||||
kwonlydefaults: Text | None
|
||||
shortsignature: Text | None
|
||||
name: Text
|
||||
doc: Text | None
|
||||
module: Text | None
|
||||
annotations: _dict[Text, Any]
|
||||
signature: Text
|
||||
dict: _dict[Text, Any]
|
||||
kwonlyargs: list[str]
|
||||
kwonlydefaults: str | None
|
||||
shortsignature: str | None
|
||||
name: str
|
||||
doc: str | None
|
||||
module: str | None
|
||||
annotations: _dict[str, Any]
|
||||
signature: str
|
||||
dict: _dict[str, Any]
|
||||
def __init__(
|
||||
self,
|
||||
func: Callable[..., Any] | None = ...,
|
||||
name: Text | None = ...,
|
||||
signature: Text | None = ...,
|
||||
name: str | None = ...,
|
||||
signature: str | None = ...,
|
||||
defaults: tuple[Any, ...] | None = ...,
|
||||
doc: Text | None = ...,
|
||||
module: Text | None = ...,
|
||||
funcdict: _dict[Text, Any] | None = ...,
|
||||
doc: str | None = ...,
|
||||
module: str | None = ...,
|
||||
funcdict: _dict[str, Any] | None = ...,
|
||||
) -> None: ...
|
||||
def update(self, func: Any, **kw: Any) -> None: ...
|
||||
def make(
|
||||
self, src_templ: Text, evaldict: _dict[Text, Any] | None = ..., addsource: bool = ..., **attrs: Any
|
||||
self, src_templ: str, evaldict: _dict[str, Any] | None = ..., addsource: bool = ..., **attrs: Any
|
||||
) -> Callable[..., Any]: ...
|
||||
@classmethod
|
||||
def create(
|
||||
cls,
|
||||
obj: Any,
|
||||
body: Text,
|
||||
evaldict: _dict[Text, Any],
|
||||
body: str,
|
||||
evaldict: _dict[str, Any],
|
||||
defaults: tuple[Any, ...] | None = ...,
|
||||
doc: Text | None = ...,
|
||||
module: Text | None = ...,
|
||||
doc: str | None = ...,
|
||||
module: str | None = ...,
|
||||
addsource: bool = ...,
|
||||
**attrs: Any,
|
||||
) -> Callable[..., Any]: ...
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Text
|
||||
from typing import Any
|
||||
from typing_extensions import final
|
||||
|
||||
GLOBAL_ACK_EINTR: int
|
||||
@@ -24,7 +24,7 @@ class Curl:
|
||||
def setopt_string(self, option: int, value: str) -> None: ...
|
||||
def perform(self) -> None: ...
|
||||
def perform_rb(self) -> bytes: ...
|
||||
def perform_rs(self) -> Text: ...
|
||||
def perform_rs(self) -> str: ...
|
||||
def getinfo(self, info: Any) -> Any: ...
|
||||
def getinfo_raw(self, info: Any) -> Any: ...
|
||||
def reset(self) -> None: ...
|
||||
|
||||
@@ -79,6 +79,15 @@ def check_new_syntax(tree: ast.AST, path: Path, stub: str) -> list[str]:
|
||||
)
|
||||
self.generic_visit(node)
|
||||
|
||||
class TextFinder(ast.NodeVisitor):
|
||||
def visit_ImportFrom(self, node: ast.ImportFrom) -> None:
|
||||
if node.module == "typing" and any(thing.name == "Text" for thing in node.names):
|
||||
errors.append(f"{path}:{node.lineno}: Use `str` instead of `typing.Text` in a Python-3-only stub.")
|
||||
|
||||
def visit_Attribute(self, node: ast.Attribute) -> None:
|
||||
if isinstance(node.value, ast.Name) and node.value.id == "typing" and node.attr == "Text":
|
||||
errors.append(f"{path}:{node.lineno}: Use `str` instead of `typing.Text` in a Python-3-only stub.")
|
||||
|
||||
class IfFinder(ast.NodeVisitor):
|
||||
def visit_If(self, node: ast.If) -> None:
|
||||
if (
|
||||
@@ -96,6 +105,8 @@ def check_new_syntax(tree: ast.AST, path: Path, stub: str) -> list[str]:
|
||||
|
||||
if not python_2_support_required:
|
||||
ObjectClassdefFinder().visit(tree)
|
||||
if path != Path("stdlib/typing_extensions.pyi"):
|
||||
TextFinder().visit(tree)
|
||||
|
||||
OldSyntaxFinder().visit(tree)
|
||||
IfFinder().visit(tree)
|
||||
|
||||
Reference in New Issue
Block a user