From 68c8548b5cbe3900d62c637bce673349cd73bb50 Mon Sep 17 00:00:00 2001 From: Jonathan Dung Date: Tue, 7 Apr 2026 01:24:11 +0800 Subject: [PATCH] [json] Use literal return type for `detect_encoding` (#15609) --- stdlib/json/__init__.pyi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stdlib/json/__init__.pyi b/stdlib/json/__init__.pyi index 63e9718ee..454a235ec 100644 --- a/stdlib/json/__init__.pyi +++ b/stdlib/json/__init__.pyi @@ -1,6 +1,6 @@ from _typeshed import SupportsRead, SupportsWrite from collections.abc import Callable -from typing import Any +from typing import Any, Literal from .decoder import JSONDecodeError as JSONDecodeError, JSONDecoder as JSONDecoder from .encoder import JSONEncoder as JSONEncoder @@ -58,4 +58,6 @@ def load( object_pairs_hook: Callable[[list[tuple[Any, Any]]], Any] | None = None, **kwds: Any, ) -> Any: ... -def detect_encoding(b: bytes | bytearray) -> str: ... # undocumented +def detect_encoding( + b: bytes | bytearray, +) -> Literal["utf-8", "utf-8-sig", "utf-16", "utf-16-be", "utf-16-le", "utf-32", "utf-32-be", "utf-32-le"]: ... # undocumented