Commit 8884fd9f authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Require exec_io deserialisers to work on memoryviews

Also switch JSON deserialiser in-use to "orjson" to work with this
change. Potential speed boosts just a bonus 😀
parent 9811868c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -89,5 +89,6 @@ repos:
  hooks:
  - id: mypy
    additional_dependencies:
    - types-orjson
    - types-requests
    - git+https://code.kodo.org.uk/dom/type-stubs.git#type-stubs[jsonpath,parse]
+3 −3
Original line number Diff line number Diff line
@@ -10,12 +10,12 @@ JSON classes for container types (objects and arrays)

from __future__ import annotations

import json
from typing import Any
from typing import Callable
from typing import TypeVar
from typing import overload

import orjson
from jsonpath import JSONPath

__all__ = [
@@ -61,7 +61,7 @@ class JSONObject(JSONPathMixin, dict[str, Any]):
		"""
		Create a JSONObject from a JSON string
		"""
		return cls(json.loads(string))
		return cls(orjson.loads(string))


class JSONArray(JSONPathMixin, list[Any]):
@@ -76,4 +76,4 @@ class JSONArray(JSONPathMixin, list[Any]):
		"""
		Create a JSONArray from a JSON string
		"""
		return cls(json.loads(string))
		return cls(orjson.loads(string))
+2 −2
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ from typing import overload
import trio.abc

T = TypeVar('T')
Deserialiser = Callable[[bytes], T]
Deserialiser = Callable[[memoryview], T]

PathLike = os.PathLike[str]
PathArg = Union[PathLike, str]
@@ -90,7 +90,7 @@ def exec_io(
	proc = trio.run(_exec_io, cmd, data, stdout, stderr, kwargs)
	if deserialiser:
		assert isinstance(stdout, io.BytesIO)
		return deserialiser(stdout.getvalue())
		return deserialiser(stdout.getbuffer())
	return proc.returncode


+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ include = [
python = "~=3.9"
behave = "~=1.2"
jsonpath-python = "~=1.0"
orjson = "~=3.6.1"
parse = "~=1.19"
requests = "~=2.26"
trio = "~=0.19"