Skip to content

Commit

Permalink
Remove deprecated from_builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist committed Oct 25, 2024
1 parent f66bbbd commit 07e2abd
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 79 deletions.
26 changes: 0 additions & 26 deletions msgspec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,6 @@ def field(*, default=NODEFAULT, default_factory=NODEFAULT, name=None):
return _Field(default=default, default_factory=default_factory, name=name)


def from_builtins(
obj,
type,
*,
str_keys=False,
str_values=False,
builtin_types=None,
dec_hook=None,
):
"""DEPRECATED: use ``msgspec.convert`` instead"""
import warnings

warnings.warn(
"`msgspec.from_builtins` is deprecated, please use `msgspec.convert` instead",
stacklevel=2,
)
return convert(
obj,
type,
strict=not str_values,
dec_hook=dec_hook,
builtin_types=builtin_types,
str_keys=str_keys,
)


field.__doc__ = _Field.__doc__


Expand Down
22 changes: 0 additions & 22 deletions msgspec/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -177,28 +177,6 @@ def convert(
str_keys: bool = False,
) -> Any: ...

# TODO: deprecated
@overload
def from_builtins(
obj: Any,
type: Type[T],
*,
str_keys: bool = False,
str_values: bool = False,
builtin_types: Union[Iterable[type], None] = None,
dec_hook: Optional[Callable[[type, Any], Any]] = None,
) -> T: ...
@overload
def from_builtins(
obj: Any,
type: Any,
*,
str_keys: bool = False,
str_values: bool = False,
builtin_types: Union[Iterable[type], None] = None,
dec_hook: Optional[Callable[[type, Any], Any]] = None,
) -> Any: ...

class MsgspecError(Exception): ...
class EncodeError(MsgspecError): ...
class DecodeError(MsgspecError): ...
Expand Down
21 changes: 0 additions & 21 deletions tests/basic_typing_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,24 +1134,3 @@ def check_convert() -> None:

o7 = msgspec.convert("1", int, str_keys=True)
reveal_type(o7) # assert "int" in typ.lower()


def check_from_builtins() -> None:
"""TODO: deprecated"""
o1 = msgspec.from_builtins(1, int)
reveal_type(o1) # assert "int" in typ.lower()

o2 = msgspec.from_builtins([1, 2], List[float])
reveal_type(o2) # assert "list" in typ.lower()

o3 = msgspec.from_builtins(1, int, str_keys=False)
reveal_type(o3) # assert "int" in typ.lower()

o4 = msgspec.from_builtins("1", int, str_values=True)
reveal_type(o4) # assert "int" in typ.lower()

o5 = msgspec.from_builtins(1, int, builtin_types=(bytes, bytearray, memoryview))
reveal_type(o5) # assert "int" in typ.lower()

o6 = msgspec.from_builtins(1, int, dec_hook=lambda typ, x: None)
reveal_type(o6) # assert "int" in typ.lower()
10 changes: 0 additions & 10 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,6 @@ def roundtrip(obj, typ):
return convert(to_builtins(obj), typ)


class TestFromBuiltins:
"""TODO: deprecated"""

def test_from_builtins(self):
with pytest.warns(UserWarning, match="deprecated"):
res = msgspec.from_builtins([1, 2], List[float])
assert res == [1.0, 2.0]
assert type(res[0]) is float


class TestConvert:
def test_bad_calls(self):
with pytest.raises(TypeError):
Expand Down

0 comments on commit 07e2abd

Please sign in to comment.