This commit is contained in:
@@ -22,7 +22,7 @@ class Protocol(str, Enum):
|
||||
pickle = 'pickle'
|
||||
|
||||
|
||||
@deprecated('load_str_bytes is deprecated.', category=PydanticDeprecatedSince20)
|
||||
@deprecated('`load_str_bytes` is deprecated.', category=None)
|
||||
def load_str_bytes(
|
||||
b: str | bytes,
|
||||
*,
|
||||
@@ -32,7 +32,7 @@ def load_str_bytes(
|
||||
allow_pickle: bool = False,
|
||||
json_loads: Callable[[str], Any] = json.loads,
|
||||
) -> Any:
|
||||
warnings.warn('load_str_bytes is deprecated.', DeprecationWarning, stacklevel=2)
|
||||
warnings.warn('`load_str_bytes` is deprecated.', category=PydanticDeprecatedSince20, stacklevel=2)
|
||||
if proto is None and content_type:
|
||||
if content_type.endswith(('json', 'javascript')):
|
||||
pass
|
||||
@@ -46,17 +46,17 @@ def load_str_bytes(
|
||||
if proto == Protocol.json:
|
||||
if isinstance(b, bytes):
|
||||
b = b.decode(encoding)
|
||||
return json_loads(b)
|
||||
return json_loads(b) # type: ignore
|
||||
elif proto == Protocol.pickle:
|
||||
if not allow_pickle:
|
||||
raise RuntimeError('Trying to decode with pickle with allow_pickle=False')
|
||||
bb = b if isinstance(b, bytes) else b.encode()
|
||||
bb = b if isinstance(b, bytes) else b.encode() # type: ignore
|
||||
return pickle.loads(bb)
|
||||
else:
|
||||
raise TypeError(f'Unknown protocol: {proto}')
|
||||
|
||||
|
||||
@deprecated('load_file is deprecated.', category=PydanticDeprecatedSince20)
|
||||
@deprecated('`load_file` is deprecated.', category=None)
|
||||
def load_file(
|
||||
path: str | Path,
|
||||
*,
|
||||
@@ -66,7 +66,7 @@ def load_file(
|
||||
allow_pickle: bool = False,
|
||||
json_loads: Callable[[str], Any] = json.loads,
|
||||
) -> Any:
|
||||
warnings.warn('load_file is deprecated.', DeprecationWarning, stacklevel=2)
|
||||
warnings.warn('`load_file` is deprecated.', category=PydanticDeprecatedSince20, stacklevel=2)
|
||||
path = Path(path)
|
||||
b = path.read_bytes()
|
||||
if content_type is None:
|
||||
|
||||
Reference in New Issue
Block a user