Never explicitly inherit from object in Python 3-only stubs (#6777)

This commit is contained in:
Alex Waygood
2022-01-02 06:24:48 +00:00
committed by GitHub
parent d43cd997a4
commit 505ea72641
35 changed files with 79 additions and 67 deletions

View File

@@ -128,6 +128,15 @@ def check_new_syntax(tree: ast.AST, path: Path) -> list[str]:
UnionFinder().visit(node.returns)
self.generic_visit(node)
class ObjectClassdefFinder(ast.NodeVisitor):
def visit_ClassDef(self, node: ast.ClassDef) -> None:
if any(isinstance(base, ast.Name) and base.id == "object" for base in node.bases):
errors.append(
f"{path}:{node.lineno}: Do not inherit from `object` explicitly, "
f"as all classes implicitly inherit from `object` in Python 3"
)
self.generic_visit(node)
class IfFinder(ast.NodeVisitor):
def visit_If(self, node: ast.If) -> None:
if (
@@ -146,6 +155,9 @@ def check_new_syntax(tree: ast.AST, path: Path) -> list[str]:
if path != Path("stdlib/typing_extensions.pyi"):
OldSyntaxFinder().visit(tree)
if not python_2_support_required:
ObjectClassdefFinder().visit(tree)
IfFinder().visit(tree)
return errors