mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-11-01 09:16:22 +08:00
Python 3 stubs: use str instead of typing.Text (#7638)
This commit is contained in:
1 parent
d802e65f67
commit
819900fa55
5 files changed
+56
-45
No files matched your search
@@ -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