From 9b4c3d432e79d72009ec7106707f50b7f3f461f2 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 23 Mar 2026 12:45:22 +0100 Subject: [PATCH] [requests] Add `requests.compat.JSONDecodeError` Also add a comment that `JSONDecodeError` may be imported from `simplejson` if that is installed. --- stubs/requests/requests/compat.pyi | 3 +++ stubs/requests/requests/exceptions.pyi | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/stubs/requests/requests/compat.pyi b/stubs/requests/requests/compat.pyi index 1d6af41632f9..f7b722222007 100644 --- a/stubs/requests/requests/compat.pyi +++ b/stubs/requests/requests/compat.pyi @@ -1,5 +1,8 @@ from builtins import bytes as bytes, str as str from collections import OrderedDict as OrderedDict + +# If simplejson is installed, JSONDecodeError is actually imported from there. +from json import JSONDecodeError as JSONDecodeError from typing import Literal from typing_extensions import TypeAlias from urllib.parse import ( diff --git a/stubs/requests/requests/exceptions.pyi b/stubs/requests/requests/exceptions.pyi index 24bfd700578c..c76e78d4f52c 100644 --- a/stubs/requests/requests/exceptions.pyi +++ b/stubs/requests/requests/exceptions.pyi @@ -1,8 +1,8 @@ -from json import JSONDecodeError as CompatJSONDecodeError from typing import Any from urllib3.exceptions import HTTPError as BaseHTTPError +from .compat import JSONDecodeError as CompatJSONDecodeError from .models import Request, Response from .sessions import PreparedRequest