__init__.pyi 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import decimal
  2. from typing import Any, Literal
  3. def from_json(
  4. json_data: bytes,
  5. /,
  6. *,
  7. allow_inf_nan: bool = True,
  8. cache_mode: Literal[True, False, "all", "keys", "none"] = "all",
  9. partial_mode: Literal[True, False, "off", "on", "trailing-strings"] = False,
  10. catch_duplicate_keys: bool = False,
  11. float_mode: Literal["float", "decimal", "lossless-float"] = "float",
  12. ) -> Any:
  13. """
  14. Parse input bytes into a JSON object.
  15. Arguments:
  16. json_data: The JSON data to parse
  17. allow_inf_nan: Whether to allow infinity (`Infinity` an `-Infinity`) and `NaN` values to float fields.
  18. Defaults to True.
  19. cache_mode: cache Python strings to improve performance at the cost of some memory usage
  20. - True / 'all' - cache all strings
  21. - 'keys' - cache only object keys
  22. - False / 'none' - cache nothing
  23. partial_mode: How to handle incomplete strings:
  24. - False / 'off' - raise an exception if the input is incomplete
  25. - True / 'on' - allow incomplete JSON but discard the last string if it is incomplete
  26. - 'trailing-strings' - allow incomplete JSON, and include the last incomplete string in the output
  27. catch_duplicate_keys: if True, raise an exception if objects contain the same key multiple times
  28. float_mode: How to return floats: as a `float`, `Decimal` or `LosslessFloat`
  29. Returns:
  30. Python object built from the JSON input.
  31. """
  32. def cache_clear() -> None:
  33. """
  34. Reset the string cache.
  35. """
  36. def cache_usage() -> int:
  37. """
  38. get the size of the string cache.
  39. Returns:
  40. Size of the string cache in bytes.
  41. """
  42. class LosslessFloat:
  43. """
  44. Represents a float from JSON, by holding the underlying bytes representing a float from JSON.
  45. """
  46. def __init__(self, json_float: bytes):
  47. """Construct a LosslessFloat object from a JSON bytes slice"""
  48. def as_decimal(self) -> decimal.Decimal:
  49. """Construct a Python Decimal from the JSON bytes slice"""
  50. def __float__(self) -> float:
  51. """Construct a Python float from the JSON bytes slice"""
  52. def __bytes__(self) -> bytes:
  53. """Return the JSON bytes slice as bytes"""
  54. def __str__(self):
  55. """Return the JSON bytes slice as a string"""
  56. def __repr__(self):
  57. ...