Skip to content

Text -> str in more py3-only stubs #7638

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
Apr 16, 2022
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
14 changes: 7 additions & 7 deletions stubs/Markdown/markdown/core.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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__(
Expand All @@ -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 = ...,
Expand All @@ -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 = ...,
Expand Down
26 changes: 13 additions & 13 deletions stubs/PyMySQL/pymysql/cursors.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand All @@ -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]
46 changes: 23 additions & 23 deletions stubs/decorator/decorator.pyi
Original file line number Diff line number Diff line change
@@ -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])
Expand Down Expand Up @@ -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]: ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/pycurl/pycurl.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Text
from typing import Any
from typing_extensions import final

GLOBAL_ACK_EINTR: int
Expand All @@ -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: ...
Expand Down
11 changes: 11 additions & 0 deletions tests/check_new_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ def visit_ClassDef(self, node: ast.ClassDef) -> None:
)
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 (
Expand All @@ -96,6 +105,8 @@ def visit_If(self, node: ast.If) -> None:

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)
Expand Down