From eaad7bb42385793a0622376caf3b832a7836781e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Wed, 14 May 2025 13:17:48 +0200 Subject: [PATCH] Fix type annotations for Python 3.14 Fix type annotations for `Provider.json()` to avoid name collision in Python 3.14.0b1 where `json` is resolved to the `json()` method itself rather than the `json` module. Import `JSONEncoder` directly instead, so we can reference it without `json.`. Fixes #2212 --- faker/providers/misc/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/faker/providers/misc/__init__.py b/faker/providers/misc/__init__.py index dca3363e..6ed2e958 100644 --- a/faker/providers/misc/__init__.py +++ b/faker/providers/misc/__init__.py @@ -9,6 +9,7 @@ import tarfile import uuid import zipfile +from json import JSONEncoder from typing import Any, Callable, Dict, List, Literal, Optional, Sequence, Set, Tuple, Type, Union, overload from faker.exceptions import UnsupportedFeature @@ -536,7 +537,7 @@ class Provider(BaseProvider): data_columns: Optional[List] = None, num_rows: int = 10, indent: Optional[int] = None, - cls: Optional[Type[json.JSONEncoder]] = None, + cls: Optional[Type[JSONEncoder]] = None, ) -> bytes: """ Generate random JSON structure and return as bytes. @@ -551,7 +552,7 @@ class Provider(BaseProvider): data_columns: Optional[List] = None, num_rows: int = 10, indent: Optional[int] = None, - cls: Optional[Type[json.JSONEncoder]] = None, + cls: Optional[Type[JSONEncoder]] = None, ) -> str: """ Generate random JSON structure values.