mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-02-25 11:07:17 +08:00
Remove Python 2 support from some third-party distributions (#7466)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
@@ -68,17 +68,9 @@ def check_stubs():
|
||||
else:
|
||||
assert name.isidentifier(), f"Bad file name '{entry}' in stubs"
|
||||
else:
|
||||
if entry in ("@python2", "@tests"):
|
||||
if entry == "@tests":
|
||||
continue
|
||||
assert_stubs_only(os.path.join("stubs", distribution, entry))
|
||||
if os.path.isdir(os.path.join("stubs", distribution, "@python2")):
|
||||
for entry in os.listdir(os.path.join("stubs", distribution, "@python2")):
|
||||
if os.path.isfile(os.path.join("stubs", distribution, "@python2", entry)):
|
||||
name, ext = os.path.splitext(entry)
|
||||
assert name.isidentifier(), f"Bad file name '{entry}' in stubs"
|
||||
assert ext == ".pyi", f"Unexpected file {entry} in @python2 stubs"
|
||||
else:
|
||||
assert_stubs_only(os.path.join("stubs", distribution, "@python2", entry))
|
||||
|
||||
|
||||
def check_same_files():
|
||||
|
||||
@@ -46,11 +46,13 @@ def check_new_syntax(tree: ast.AST, path: Path) -> list[str]:
|
||||
|
||||
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"
|
||||
)
|
||||
# Temporarily disable this check for two ex-Python 2 stubs.
|
||||
if "paramiko" not in str(path) and "cryptography" not in str(path):
|
||||
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):
|
||||
|
||||
@@ -101,7 +101,7 @@ def is_supported(distribution, major):
|
||||
data = dict(tomli.loads(f.read()))
|
||||
if major == 2:
|
||||
# Python 2 is not supported by default.
|
||||
return bool(data.get("python2", False)) or (dist_path / "@python2").exists()
|
||||
return bool(data.get("python2", False))
|
||||
# Python 3 is supported by default.
|
||||
return has_py3_stubs(dist_path)
|
||||
|
||||
@@ -246,13 +246,8 @@ def add_third_party_files(
|
||||
for dependency in dependencies:
|
||||
add_third_party_files(dependency, major, files, args, configurations, seen_dists)
|
||||
|
||||
if major == 2 and os.path.isdir(os.path.join("stubs", distribution, "@python2")):
|
||||
root = os.path.join("stubs", distribution, "@python2")
|
||||
else:
|
||||
root = os.path.join("stubs", distribution)
|
||||
root = os.path.join("stubs", distribution)
|
||||
for name in os.listdir(root):
|
||||
if name == "@python2":
|
||||
continue
|
||||
mod, _ = os.path.splitext(name)
|
||||
if mod.startswith("."):
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user