Restrict filename parameter of compile() (and other stdlib functions wrapping compile()) to take bytes, not Buffer. (#14847)

This commit is contained in:
Thanos
2025-10-08 10:32:16 -04:00
committed by GitHub
parent 12e7d4e9cf
commit be7e7c5e2b
4 changed files with 19 additions and 19 deletions
+2 -2
View File
@@ -100,7 +100,7 @@ class SourceLoader(_LoaderBasics):
def get_source(self, fullname: str) -> str | None: ...
def path_stats(self, path: str) -> Mapping[str, Any]: ...
def source_to_code(
self, data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, path: ReadableBuffer | StrPath
self, data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, path: bytes | StrPath
) -> types.CodeType: ...
def get_code(self, fullname: str) -> types.CodeType | None: ...
@@ -126,7 +126,7 @@ class SourceFileLoader(importlib.abc.FileLoader, FileLoader, importlib.abc.Sourc
def source_to_code( # type: ignore[override] # incompatible with InspectLoader.source_to_code
self,
data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive,
path: ReadableBuffer | StrPath,
path: bytes | StrPath,
*,
_optimize: int = -1,
) -> types.CodeType: ...
+12 -12
View File
@@ -1747,7 +1747,7 @@ if sys.version_info >= (3, 13):
@overload
def parse(
source: _T,
filename: str | ReadableBuffer | os.PathLike[Any] = "<unknown>",
filename: str | bytes | os.PathLike[Any] = "<unknown>",
mode: Literal["exec", "eval", "func_type", "single"] = "exec",
*,
type_comments: bool = False,
@@ -1757,7 +1757,7 @@ if sys.version_info >= (3, 13):
@overload
def parse(
source: str | ReadableBuffer,
filename: str | ReadableBuffer | os.PathLike[Any] = "<unknown>",
filename: str | bytes | os.PathLike[Any] = "<unknown>",
mode: Literal["exec"] = "exec",
*,
type_comments: bool = False,
@@ -1767,7 +1767,7 @@ if sys.version_info >= (3, 13):
@overload
def parse(
source: str | ReadableBuffer,
filename: str | ReadableBuffer | os.PathLike[Any],
filename: str | bytes | os.PathLike[Any],
mode: Literal["eval"],
*,
type_comments: bool = False,
@@ -1777,7 +1777,7 @@ if sys.version_info >= (3, 13):
@overload
def parse(
source: str | ReadableBuffer,
filename: str | ReadableBuffer | os.PathLike[Any],
filename: str | bytes | os.PathLike[Any],
mode: Literal["func_type"],
*,
type_comments: bool = False,
@@ -1787,7 +1787,7 @@ if sys.version_info >= (3, 13):
@overload
def parse(
source: str | ReadableBuffer,
filename: str | ReadableBuffer | os.PathLike[Any],
filename: str | bytes | os.PathLike[Any],
mode: Literal["single"],
*,
type_comments: bool = False,
@@ -1824,7 +1824,7 @@ if sys.version_info >= (3, 13):
@overload
def parse(
source: str | ReadableBuffer,
filename: str | ReadableBuffer | os.PathLike[Any] = "<unknown>",
filename: str | bytes | os.PathLike[Any] = "<unknown>",
mode: str = "exec",
*,
type_comments: bool = False,
@@ -1836,7 +1836,7 @@ else:
@overload
def parse(
source: _T,
filename: str | ReadableBuffer | os.PathLike[Any] = "<unknown>",
filename: str | bytes | os.PathLike[Any] = "<unknown>",
mode: Literal["exec", "eval", "func_type", "single"] = "exec",
*,
type_comments: bool = False,
@@ -1845,7 +1845,7 @@ else:
@overload
def parse(
source: str | ReadableBuffer,
filename: str | ReadableBuffer | os.PathLike[Any] = "<unknown>",
filename: str | bytes | os.PathLike[Any] = "<unknown>",
mode: Literal["exec"] = "exec",
*,
type_comments: bool = False,
@@ -1854,7 +1854,7 @@ else:
@overload
def parse(
source: str | ReadableBuffer,
filename: str | ReadableBuffer | os.PathLike[Any],
filename: str | bytes | os.PathLike[Any],
mode: Literal["eval"],
*,
type_comments: bool = False,
@@ -1863,7 +1863,7 @@ else:
@overload
def parse(
source: str | ReadableBuffer,
filename: str | ReadableBuffer | os.PathLike[Any],
filename: str | bytes | os.PathLike[Any],
mode: Literal["func_type"],
*,
type_comments: bool = False,
@@ -1872,7 +1872,7 @@ else:
@overload
def parse(
source: str | ReadableBuffer,
filename: str | ReadableBuffer | os.PathLike[Any],
filename: str | bytes | os.PathLike[Any],
mode: Literal["single"],
*,
type_comments: bool = False,
@@ -1905,7 +1905,7 @@ else:
@overload
def parse(
source: str | ReadableBuffer,
filename: str | ReadableBuffer | os.PathLike[Any] = "<unknown>",
filename: str | bytes | os.PathLike[Any] = "<unknown>",
mode: str = "exec",
*,
type_comments: bool = False,
+4 -4
View File
@@ -1401,7 +1401,7 @@ if sys.version_info >= (3, 10):
@overload
def compile(
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
filename: str | ReadableBuffer | PathLike[Any],
filename: str | bytes | PathLike[Any],
mode: str,
flags: Literal[0],
dont_inherit: bool = False,
@@ -1412,7 +1412,7 @@ def compile(
@overload
def compile(
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
filename: str | ReadableBuffer | PathLike[Any],
filename: str | bytes | PathLike[Any],
mode: str,
*,
dont_inherit: bool = False,
@@ -1422,7 +1422,7 @@ def compile(
@overload
def compile(
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
filename: str | ReadableBuffer | PathLike[Any],
filename: str | bytes | PathLike[Any],
mode: str,
flags: Literal[1024],
dont_inherit: bool = False,
@@ -1433,7 +1433,7 @@ def compile(
@overload
def compile(
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
filename: str | ReadableBuffer | PathLike[Any],
filename: str | bytes | PathLike[Any],
mode: str,
flags: int,
dont_inherit: bool = False,
+1 -1
View File
@@ -53,7 +53,7 @@ class InspectLoader(Loader):
def exec_module(self, module: types.ModuleType) -> None: ...
@staticmethod
def source_to_code(
data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, path: ReadableBuffer | StrPath = "<string>"
data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, path: bytes | StrPath = "<string>"
) -> types.CodeType: ...
class ExecutionLoader(InspectLoader):