structtype 0.4.0__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {structtype-0.4.0 → structtype-0.6.0}/AGENTS.md +7 -6
- {structtype-0.4.0 → structtype-0.6.0}/Makefile +18 -6
- {structtype-0.4.0 → structtype-0.6.0}/PKG-INFO +20 -5
- {structtype-0.4.0 → structtype-0.6.0}/README.md +15 -2
- {structtype-0.4.0 → structtype-0.6.0}/pyproject.toml +21 -27
- structtype-0.6.0/src/structtype/__init__.py +42 -0
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype/__init__.pyi +58 -55
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype/_adapter.py +43 -50
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype/_core.c +876 -856
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype/_inspect.py +29 -29
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype/_json_schema.py +15 -14
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype/_utils.py +23 -21
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype/_version.py +2 -2
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype.egg-info/PKG-INFO +20 -5
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype.egg-info/SOURCES.txt +7 -12
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_adapter.py +195 -1
- structtype-0.6.0/tests/test_attrs.py +52 -0
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_constraints.py +7 -1
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_free_threading.py +45 -0
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_inspect.py +59 -7
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_json.py +346 -266
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_memory.py +0 -20
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_pydantic.py +33 -0
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_schema.py +49 -1
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_struct.py +132 -212
- structtype-0.6.0/tests/test_typecheck.py +51 -0
- structtype-0.6.0/tests/typecheck/api.py +62 -0
- structtype-0.6.0/tests/typecheck/basic.py +63 -0
- structtype-0.6.0/tests/typecheck/fields.py +47 -0
- structtype-0.6.0/tests/typecheck/types.py +100 -0
- {structtype-0.4.0 → structtype-0.6.0}/uv.lock +172 -94
- structtype-0.4.0/graphify-out/.graphify_labels.json +0 -108
- structtype-0.4.0/graphify-out/.graphify_labels.json.sig +0 -1
- structtype-0.4.0/graphify-out/.graphify_root +0 -1
- structtype-0.4.0/graphify-out/2026-08-09/.graphify_labels.json +0 -93
- structtype-0.4.0/graphify-out/2026-08-09/GRAPH_REPORT.md +0 -385
- structtype-0.4.0/graphify-out/2026-08-09/graph.json +0 -75971
- structtype-0.4.0/graphify-out/2026-08-09/manifest.json +0 -332
- structtype-0.4.0/graphify-out/GRAPH_REPORT.md +0 -448
- structtype-0.4.0/graphify-out/graph.html +0 -320
- structtype-0.4.0/graphify-out/graph.json +0 -77910
- structtype-0.4.0/graphify-out/manifest.json +0 -327
- structtype-0.4.0/src/structtype/__init__.py +0 -18
- {structtype-0.4.0 → structtype-0.6.0}/.opencode/opencode.json +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/.opencode/plugins/graphify.js +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/LICENSE +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/MANIFEST.in +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/setup.cfg +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/setup.py +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype/atof.h +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype/atof_consts.h +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype/common.h +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype/itoa.h +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype/py.typed +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype/ryu.h +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype.egg-info/dependency_links.txt +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/src/structtype.egg-info/top_level.txt +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/tests/__init__.py +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/tests/conftest.py +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_JSONTestSuite.py +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_check.py +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_cpylint.py +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_msgspec.py +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_raw.py +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_struct_meta.py +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/tests/test_utils.py +0 -0
- {structtype-0.4.0 → structtype-0.6.0}/tests/utils.py +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## Project
|
|
4
4
|
|
|
5
5
|
Fast struct validation + JSON serialization for Python.
|
|
6
|
-
Core is a monolithic C extension (`src/structtype/_core.c`, ~
|
|
6
|
+
Core is a monolithic C extension (`src/structtype/_core.c`, ~19K lines).
|
|
7
7
|
No runtime deps.
|
|
8
8
|
|
|
9
9
|
## Setup
|
|
@@ -47,11 +47,11 @@ All commands go through `make`.
|
|
|
47
47
|
|
|
48
48
|
### Struct Methods
|
|
49
49
|
|
|
50
|
-
- `obj.struct_dump_json(*,
|
|
51
|
-
- `obj.struct_dump()` — convert to built-in Python types (uses `
|
|
50
|
+
- `obj.struct_dump_json(*, decimal_format=None, uuid_format=None, sort_keys=False)` — serialize to JSON bytes
|
|
51
|
+
- `obj.struct_dump(*, sort_keys=False, str_keys=False, builtin_types=None)` — convert to built-in Python types (uses `alias` for keys)
|
|
52
52
|
- `obj.struct_validate_self()` — validate field values against types + constraints
|
|
53
|
-
- `cls.struct_validate_json(buf, *, strict=True
|
|
54
|
-
- `cls.struct_validate(obj, *, strict=True, from_attributes=False
|
|
53
|
+
- `cls.struct_validate_json(buf, *, strict=True)` — deserialize from JSON
|
|
54
|
+
- `cls.struct_validate(obj, *, strict=True, from_attributes=False)` — convert built-in types to struct
|
|
55
55
|
|
|
56
56
|
### Dict & Iteration Protocol
|
|
57
57
|
|
|
@@ -61,7 +61,8 @@ Struct instances support the mapping protocol:
|
|
|
61
61
|
|
|
62
62
|
## Gotchas
|
|
63
63
|
|
|
64
|
-
- `make test-
|
|
64
|
+
- `make test-cov` reinstalls the C extension before running (last-failed first)
|
|
65
|
+
- Validation matches keys by the **alias** name only, except `struct_validate(obj, from_attributes=True)` on a **non-dict object**, which matches by both the python field name and the alias. Dict/JSON input (even with `from_attributes=True`) and all dump/serialization use only the alias name.
|
|
65
66
|
|
|
66
67
|
## graphify
|
|
67
68
|
|
|
@@ -23,7 +23,7 @@ wheels: ## build wheels
|
|
|
23
23
|
|
|
24
24
|
##@ Quality
|
|
25
25
|
.PHONY: test-cov
|
|
26
|
-
test-cov: ## Run tests with coverage
|
|
26
|
+
test-cov: build ## Run tests with coverage
|
|
27
27
|
uv run pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=structtype
|
|
28
28
|
|
|
29
29
|
.PHONY: test-lf
|
|
@@ -34,11 +34,17 @@ test-lf: ## Run tests in current Python
|
|
|
34
34
|
test-doc: ## Run doctests
|
|
35
35
|
uv run pytest --doctest-modules --pyargs structtype
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
TEST_ALL_TARGETS = $(PY_VERSIONS:%=test-all-%)
|
|
38
|
+
|
|
39
|
+
.PHONY: test-all $(TEST_ALL_TARGETS)
|
|
40
|
+
test-all: $(TEST_ALL_TARGETS) ## Run tests in all supported Python versions (parallel: make -j$(nproc) test-all)
|
|
41
|
+
|
|
42
|
+
define test-all-rule
|
|
43
|
+
.PHONY: test-all-$(1)
|
|
44
|
+
test-all-$(1): ## Run tests for Python $(1)
|
|
45
|
+
uv run --isolated --reinstall-package structtype -p $(1) pytest
|
|
46
|
+
endef
|
|
47
|
+
$(foreach py_v,$(PY_VERSIONS),$(eval $(call test-all-rule,$(py_v))))
|
|
42
48
|
|
|
43
49
|
UNAME_S := $(shell uname -s)
|
|
44
50
|
ifeq ($(UNAME_S),Darwin)
|
|
@@ -74,6 +80,12 @@ type-check: ## Type check with
|
|
|
74
80
|
-uvx ty check ${SOURCE_DIR}
|
|
75
81
|
uvx pyrefly check ${SOURCE_DIR}
|
|
76
82
|
|
|
83
|
+
.PHONY: typecheck-tests
|
|
84
|
+
typecheck-tests: ## Type check tests/typecheck fixtures (skipped when tools unavailable)
|
|
85
|
+
@if uvx ty --version >/dev/null 2>&1; then uvx ty check tests/typecheck; else echo "skip: ty unavailable"; fi
|
|
86
|
+
@if uvx pyrefly --version >/dev/null 2>&1; then uvx pyrefly check tests/typecheck; else echo "skip: pyrefly unavailable"; fi
|
|
87
|
+
@if uvx mypy --version >/dev/null 2>&1; then uvx mypy --python-executable .venv/bin/python tests/typecheck; else echo "skip: mypy unavailable"; fi
|
|
88
|
+
|
|
77
89
|
.PHONY: format
|
|
78
90
|
format: ## Format files using ruff format
|
|
79
91
|
uvx ruff format ${SOURCE_DIR}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: structtype
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Fast Struct type with validation and JSON serialization for Python.
|
|
5
5
|
Maintainer-email: Wolfgang Langner <tds333@mailbox.org>
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
7
|
-
Project-URL: Homepage, https://github.
|
|
7
|
+
Project-URL: Homepage, https://tds333.github.io/structtype/
|
|
8
|
+
Project-URL: Documentation, https://tds333.github.io/structtype/
|
|
9
|
+
Project-URL: Repository, https://github.com/tds333/structtype
|
|
10
|
+
Project-URL: Changelog, https://tds333.github.io/structtype/changelog.html
|
|
8
11
|
Project-URL: Issue Tracker, https://github.com/tds333/structtype/issues
|
|
9
|
-
Project-URL: Source, https://github.com/tds333/structtype
|
|
10
12
|
Keywords: JSON,schema,serialization,struct,validation
|
|
11
13
|
Classifier: Development Status :: 4 - Beta
|
|
12
14
|
Classifier: Environment :: WebAssembly :: Emscripten
|
|
@@ -23,7 +25,11 @@ Dynamic: license-file
|
|
|
23
25
|
|
|
24
26
|
# structtype
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
[](https://pypi.org/project/structtype/)
|
|
29
|
+
[](https://pypi.org/project/structtype/)
|
|
30
|
+
[](https://github.com/tds333/structtype/actions/workflows/build.yml)
|
|
31
|
+
|
|
32
|
+
Fast data struct type with validation + JSON serialization for Python.
|
|
27
33
|
|
|
28
34
|
- **High performance** — 5-60x faster than dataclasses, attrs, or pydantic for common operations
|
|
29
35
|
- **Schema validation** — familiar Python type annotations, enforced at decode time
|
|
@@ -72,7 +78,16 @@ Full documentation is available at **https://tds333.github.io/structtype/**.
|
|
|
72
78
|
|
|
73
79
|
## Benchmarks
|
|
74
80
|
|
|
75
|
-
structtype is as fast as msgspec and about 3-5x faster than pydantic.
|
|
81
|
+
structtype is as fast as msgspec and about 3-5x faster than pydantic. See the
|
|
82
|
+
[benchmarks page](https://tds333.github.io/structtype/benchmarks.html) for the full numbers.
|
|
83
|
+
|
|
84
|
+
## Links
|
|
85
|
+
|
|
86
|
+
- [Documentation](https://tds333.github.io/structtype/)
|
|
87
|
+
- [Changelog](https://tds333.github.io/structtype/changelog.html)
|
|
88
|
+
- [PyPI](https://pypi.org/project/structtype/)
|
|
89
|
+
- [Source code](https://github.com/tds333/structtype)
|
|
90
|
+
- [Issue tracker](https://github.com/tds333/structtype/issues)
|
|
76
91
|
|
|
77
92
|
## License
|
|
78
93
|
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# structtype
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://pypi.org/project/structtype/)
|
|
4
|
+
[](https://pypi.org/project/structtype/)
|
|
5
|
+
[](https://github.com/tds333/structtype/actions/workflows/build.yml)
|
|
6
|
+
|
|
7
|
+
Fast data struct type with validation + JSON serialization for Python.
|
|
4
8
|
|
|
5
9
|
- **High performance** — 5-60x faster than dataclasses, attrs, or pydantic for common operations
|
|
6
10
|
- **Schema validation** — familiar Python type annotations, enforced at decode time
|
|
@@ -49,7 +53,16 @@ Full documentation is available at **https://tds333.github.io/structtype/**.
|
|
|
49
53
|
|
|
50
54
|
## Benchmarks
|
|
51
55
|
|
|
52
|
-
structtype is as fast as msgspec and about 3-5x faster than pydantic.
|
|
56
|
+
structtype is as fast as msgspec and about 3-5x faster than pydantic. See the
|
|
57
|
+
[benchmarks page](https://tds333.github.io/structtype/benchmarks.html) for the full numbers.
|
|
58
|
+
|
|
59
|
+
## Links
|
|
60
|
+
|
|
61
|
+
- [Documentation](https://tds333.github.io/structtype/)
|
|
62
|
+
- [Changelog](https://tds333.github.io/structtype/changelog.html)
|
|
63
|
+
- [PyPI](https://pypi.org/project/structtype/)
|
|
64
|
+
- [Source code](https://github.com/tds333/structtype)
|
|
65
|
+
- [Issue tracker](https://github.com/tds333/structtype/issues)
|
|
53
66
|
|
|
54
67
|
## License
|
|
55
68
|
|
|
@@ -4,19 +4,9 @@ description = "Fast Struct type with validation and JSON serialization for Pytho
|
|
|
4
4
|
readme = "README.md"
|
|
5
5
|
requires-python = ">=3.10"
|
|
6
6
|
license = "BSD-3-Clause"
|
|
7
|
-
license-files = [
|
|
8
|
-
|
|
9
|
-
]
|
|
10
|
-
maintainers = [
|
|
11
|
-
{ name = "Wolfgang Langner", email = "tds333@mailbox.org" },
|
|
12
|
-
]
|
|
13
|
-
keywords = [
|
|
14
|
-
"JSON",
|
|
15
|
-
"schema",
|
|
16
|
-
"serialization",
|
|
17
|
-
"struct",
|
|
18
|
-
"validation",
|
|
19
|
-
]
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
maintainers = [{ name = "Wolfgang Langner", email = "tds333@mailbox.org" }]
|
|
9
|
+
keywords = ["JSON", "schema", "serialization", "struct", "validation"]
|
|
20
10
|
classifiers = [
|
|
21
11
|
"Development Status :: 4 - Beta",
|
|
22
12
|
"Environment :: WebAssembly :: Emscripten",
|
|
@@ -28,23 +18,24 @@ classifiers = [
|
|
|
28
18
|
"Programming Language :: Python :: 3.15",
|
|
29
19
|
]
|
|
30
20
|
dependencies = []
|
|
31
|
-
dynamic = [
|
|
32
|
-
"version",
|
|
33
|
-
]
|
|
21
|
+
dynamic = ["version"]
|
|
34
22
|
|
|
35
23
|
[project.urls]
|
|
36
|
-
Homepage = "https://github.
|
|
24
|
+
Homepage = "https://tds333.github.io/structtype/"
|
|
25
|
+
Documentation = "https://tds333.github.io/structtype/"
|
|
26
|
+
Repository = "https://github.com/tds333/structtype"
|
|
27
|
+
Changelog = "https://tds333.github.io/structtype/changelog.html"
|
|
37
28
|
"Issue Tracker" = "https://github.com/tds333/structtype/issues"
|
|
38
|
-
Source = "https://github.com/tds333/structtype"
|
|
39
29
|
|
|
40
30
|
[dependency-groups]
|
|
41
31
|
dev = [
|
|
42
32
|
"attrs",
|
|
43
33
|
"coverage",
|
|
44
34
|
"msgspec",
|
|
45
|
-
"pydantic; python_version < '3.
|
|
35
|
+
"pydantic; python_version < '3.16'",
|
|
46
36
|
"pytest>=9",
|
|
47
37
|
"pytest-coverage>=0.0",
|
|
38
|
+
"typing_extensions",
|
|
48
39
|
]
|
|
49
40
|
docs = [
|
|
50
41
|
"furo",
|
|
@@ -56,10 +47,7 @@ docs = [
|
|
|
56
47
|
]
|
|
57
48
|
|
|
58
49
|
[build-system]
|
|
59
|
-
requires = [
|
|
60
|
-
"setuptools>=80",
|
|
61
|
-
"setuptools-scm>=8",
|
|
62
|
-
]
|
|
50
|
+
requires = ["setuptools>=80", "setuptools-scm>=8"]
|
|
63
51
|
build-backend = "setuptools.build_meta"
|
|
64
52
|
|
|
65
53
|
[tool.setuptools]
|
|
@@ -69,10 +57,7 @@ packages = ["structtype"]
|
|
|
69
57
|
"" = "src"
|
|
70
58
|
|
|
71
59
|
[tool.setuptools.exclude-package-data]
|
|
72
|
-
structtype = [
|
|
73
|
-
"*.c",
|
|
74
|
-
"*.h",
|
|
75
|
-
]
|
|
60
|
+
structtype = ["*.c", "*.h"]
|
|
76
61
|
|
|
77
62
|
[tool.setuptools_scm]
|
|
78
63
|
version_file = "src/structtype/_version.py"
|
|
@@ -88,3 +73,12 @@ test-command = "pip install pytest>=9 && pytest {project}/tests"
|
|
|
88
73
|
|
|
89
74
|
[tool.ruff]
|
|
90
75
|
target-version = "py310"
|
|
76
|
+
|
|
77
|
+
[tool.coverage.report]
|
|
78
|
+
exclude_lines = [
|
|
79
|
+
'pragma: no cover',
|
|
80
|
+
'if (typing\.)?TYPE_CHECKING:',
|
|
81
|
+
'if sys\.version_info',
|
|
82
|
+
'except ImportError:',
|
|
83
|
+
'# noqa: F821',
|
|
84
|
+
]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from ._adapter import StructAdapter
|
|
2
|
+
from ._core import ( # type: ignore
|
|
3
|
+
ALL_BUILTIN_TYPES,
|
|
4
|
+
NODEFAULT,
|
|
5
|
+
UNSET,
|
|
6
|
+
DecodeError,
|
|
7
|
+
EncodeError,
|
|
8
|
+
Factory,
|
|
9
|
+
Field,
|
|
10
|
+
Raw,
|
|
11
|
+
Struct,
|
|
12
|
+
StructConfig,
|
|
13
|
+
StructMeta,
|
|
14
|
+
UnsetType,
|
|
15
|
+
ValidationError,
|
|
16
|
+
)
|
|
17
|
+
from ._inspect import FieldInfo, fields
|
|
18
|
+
from ._json_schema import json_schema, json_schema_components, json_schema_dump
|
|
19
|
+
from ._version import __version__
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"ALL_BUILTIN_TYPES",
|
|
23
|
+
"NODEFAULT",
|
|
24
|
+
"UNSET",
|
|
25
|
+
"DecodeError",
|
|
26
|
+
"EncodeError",
|
|
27
|
+
"Factory",
|
|
28
|
+
"Field",
|
|
29
|
+
"FieldInfo",
|
|
30
|
+
"Raw",
|
|
31
|
+
"Struct",
|
|
32
|
+
"StructAdapter",
|
|
33
|
+
"StructConfig",
|
|
34
|
+
"StructMeta",
|
|
35
|
+
"UnsetType",
|
|
36
|
+
"ValidationError",
|
|
37
|
+
"__version__",
|
|
38
|
+
"fields",
|
|
39
|
+
"json_schema",
|
|
40
|
+
"json_schema_components",
|
|
41
|
+
"json_schema_dump",
|
|
42
|
+
]
|
|
@@ -1,11 +1,34 @@
|
|
|
1
|
+
# ruff: noqa: PYI041, PYI015, PYI020, UP037
|
|
1
2
|
import enum
|
|
2
3
|
from collections.abc import Callable, Iterable, Iterator, Mapping
|
|
3
4
|
from inspect import Signature
|
|
4
|
-
from typing import
|
|
5
|
+
from typing import (
|
|
6
|
+
Any,
|
|
7
|
+
ClassVar,
|
|
8
|
+
Final,
|
|
9
|
+
Literal,
|
|
10
|
+
TypeAlias,
|
|
11
|
+
TypeVar,
|
|
12
|
+
final,
|
|
13
|
+
overload,
|
|
14
|
+
)
|
|
5
15
|
|
|
6
16
|
from typing_extensions import Buffer, Self, dataclass_transform
|
|
7
17
|
|
|
8
|
-
|
|
18
|
+
class StructConfig:
|
|
19
|
+
frozen: bool
|
|
20
|
+
eq: bool
|
|
21
|
+
order: bool
|
|
22
|
+
array_like: bool
|
|
23
|
+
repr_omit_defaults: bool
|
|
24
|
+
omit_defaults: bool
|
|
25
|
+
forbid_unknown_fields: bool
|
|
26
|
+
validate_on_init: bool
|
|
27
|
+
weakref: bool
|
|
28
|
+
dict: bool
|
|
29
|
+
cache_hash: bool
|
|
30
|
+
tag: str | int | None
|
|
31
|
+
tag_field: str | None
|
|
9
32
|
|
|
10
33
|
# PEP 673 explicitly rejects using Self in metaclass definitions:
|
|
11
34
|
# https://peps.python.org/pep-0673/#valid-locations-for-self
|
|
@@ -17,8 +40,8 @@ _SM = TypeVar("_SM", bound="StructMeta")
|
|
|
17
40
|
class StructMeta(type):
|
|
18
41
|
__struct_fields__: ClassVar[tuple[str, ...]]
|
|
19
42
|
__struct_defaults__: ClassVar[tuple[Any, ...]]
|
|
20
|
-
|
|
21
|
-
__match_args__: ClassVar[tuple[str, ...]]
|
|
43
|
+
__struct_alias_fields__: ClassVar[tuple[str, ...]]
|
|
44
|
+
__match_args__: ClassVar[tuple[str, ...]] = ...
|
|
22
45
|
@property
|
|
23
46
|
def __signature__(self) -> Signature: ...
|
|
24
47
|
@property
|
|
@@ -46,15 +69,12 @@ class StructMeta(type):
|
|
|
46
69
|
kw_only: bool = False,
|
|
47
70
|
repr_omit_defaults: bool = False,
|
|
48
71
|
array_like: bool = False,
|
|
49
|
-
gc: bool = True,
|
|
50
72
|
weakref: bool = False,
|
|
51
73
|
dict: bool = False,
|
|
52
74
|
cache_hash: bool = False,
|
|
53
75
|
validate_on_init: bool = False,
|
|
54
76
|
) -> _SM: ...
|
|
55
77
|
|
|
56
|
-
_T = TypeVar("_T")
|
|
57
|
-
|
|
58
78
|
@final
|
|
59
79
|
class UnsetType(enum.Enum):
|
|
60
80
|
UNSET = "UNSET"
|
|
@@ -68,13 +88,13 @@ class _NoDefault(enum.Enum):
|
|
|
68
88
|
|
|
69
89
|
NODEFAULT: Final = _NoDefault.NODEFAULT
|
|
70
90
|
|
|
71
|
-
@dataclass_transform(field_specifiers=("Field",))
|
|
91
|
+
@dataclass_transform(field_specifiers=("Field",)) # type: ignore
|
|
72
92
|
class Struct(metaclass=StructMeta):
|
|
73
93
|
__struct_fields__: ClassVar[tuple[str, ...]]
|
|
74
94
|
__struct_config__: ClassVar[StructConfig]
|
|
75
|
-
|
|
95
|
+
__struct_alias_fields__: ClassVar[tuple[str, ...]]
|
|
76
96
|
__struct_defaults__: ClassVar[tuple[Any, ...]]
|
|
77
|
-
__match_args__: ClassVar[tuple[str, ...]]
|
|
97
|
+
__match_args__: ClassVar[tuple[str, ...]] = ...
|
|
78
98
|
# A default __init__ so that Structs with unknown field types
|
|
79
99
|
# won't error on every call to `__init__`
|
|
80
100
|
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
|
|
@@ -96,7 +116,6 @@ class Struct(metaclass=StructMeta):
|
|
|
96
116
|
kw_only: bool = False,
|
|
97
117
|
repr_omit_defaults: bool = False,
|
|
98
118
|
array_like: bool = False,
|
|
99
|
-
gc: bool = True,
|
|
100
119
|
weakref: bool = False,
|
|
101
120
|
dict: bool = False,
|
|
102
121
|
cache_hash: bool = False,
|
|
@@ -110,7 +129,6 @@ class Struct(metaclass=StructMeta):
|
|
|
110
129
|
def struct_dump_json(
|
|
111
130
|
self,
|
|
112
131
|
*,
|
|
113
|
-
enc_hook: Callable[[Any], Any] | None = None,
|
|
114
132
|
decimal_format: Literal["string", "number"]
|
|
115
133
|
| Callable[[Any], Any]
|
|
116
134
|
| None = None,
|
|
@@ -120,7 +138,6 @@ class Struct(metaclass=StructMeta):
|
|
|
120
138
|
def struct_dump(
|
|
121
139
|
self,
|
|
122
140
|
*,
|
|
123
|
-
enc_hook: Callable[[Any], Any] | None = None,
|
|
124
141
|
sort_keys: bool = False,
|
|
125
142
|
str_keys: bool = False,
|
|
126
143
|
builtin_types: Iterable[type] | None = None,
|
|
@@ -128,21 +145,19 @@ class Struct(metaclass=StructMeta):
|
|
|
128
145
|
def struct_validate_self(self) -> None: ...
|
|
129
146
|
@classmethod
|
|
130
147
|
def struct_validate_json(
|
|
131
|
-
cls
|
|
148
|
+
cls,
|
|
132
149
|
buf: str | Buffer,
|
|
133
150
|
*,
|
|
134
151
|
strict: bool = True,
|
|
135
|
-
|
|
136
|
-
) -> _T: ...
|
|
152
|
+
) -> Self: ...
|
|
137
153
|
@classmethod
|
|
138
154
|
def struct_validate(
|
|
139
|
-
cls
|
|
155
|
+
cls,
|
|
140
156
|
obj: Any,
|
|
141
157
|
*,
|
|
142
158
|
strict: bool = True,
|
|
143
159
|
from_attributes: bool = False,
|
|
144
|
-
|
|
145
|
-
) -> _T: ...
|
|
160
|
+
) -> Self: ...
|
|
146
161
|
|
|
147
162
|
# Lie and say `Raw` is a subclass of `bytes`, so mypy will accept it in most
|
|
148
163
|
# places where an object that implements the buffer protocol is valid
|
|
@@ -157,6 +172,11 @@ class Raw(bytes):
|
|
|
157
172
|
#: We can't represent this in types, only via a name:
|
|
158
173
|
_NonNegativeInt: TypeAlias = int
|
|
159
174
|
|
|
175
|
+
@final
|
|
176
|
+
class Factory:
|
|
177
|
+
def __new__(cls, factory: Callable[[], Any]) -> Any: ...
|
|
178
|
+
factory: Final[Callable[[], Any]]
|
|
179
|
+
|
|
160
180
|
@final
|
|
161
181
|
class Field:
|
|
162
182
|
# Numeric:
|
|
@@ -167,13 +187,14 @@ class Field:
|
|
|
167
187
|
gt: int | float | None = None,
|
|
168
188
|
lt: int | float | None = None,
|
|
169
189
|
multiple_of: int | float | None = None,
|
|
170
|
-
default: Any = NODEFAULT,
|
|
171
|
-
default_factory: Callable[[], Any] | None = None,
|
|
172
190
|
alias: str | None = None,
|
|
173
191
|
title: str | None = None,
|
|
174
192
|
description: str | None = None,
|
|
175
193
|
json_schema_extra: dict[str, Any] | None = None,
|
|
176
194
|
examples: list[Any] | None = None,
|
|
195
|
+
deprecated: bool | None = None,
|
|
196
|
+
dump: Callable[[Any], Any] | None = None,
|
|
197
|
+
validate: Callable[[Any], Any] | None = None,
|
|
177
198
|
) -> None: ...
|
|
178
199
|
@overload
|
|
179
200
|
def __init__(
|
|
@@ -182,13 +203,14 @@ class Field:
|
|
|
182
203
|
gt: int | float | None = None,
|
|
183
204
|
le: int | float | None = None,
|
|
184
205
|
multiple_of: int | float | None = None,
|
|
185
|
-
default: Any = NODEFAULT,
|
|
186
|
-
default_factory: Callable[[], Any] | None = None,
|
|
187
206
|
alias: str | None = None,
|
|
188
207
|
title: str | None = None,
|
|
189
208
|
description: str | None = None,
|
|
190
209
|
json_schema_extra: dict[str, Any] | None = None,
|
|
191
210
|
examples: list[Any] | None = None,
|
|
211
|
+
deprecated: bool | None = None,
|
|
212
|
+
dump: Callable[[Any], Any] | None = None,
|
|
213
|
+
validate: Callable[[Any], Any] | None = None,
|
|
192
214
|
) -> None: ...
|
|
193
215
|
@overload
|
|
194
216
|
def __init__(
|
|
@@ -197,13 +219,14 @@ class Field:
|
|
|
197
219
|
ge: int | float | None = None,
|
|
198
220
|
lt: int | float | None = None,
|
|
199
221
|
multiple_of: int | float | None = None,
|
|
200
|
-
default: Any = NODEFAULT,
|
|
201
|
-
default_factory: Callable[[], Any] | None = None,
|
|
202
222
|
alias: str | None = None,
|
|
203
223
|
title: str | None = None,
|
|
204
224
|
description: str | None = None,
|
|
205
225
|
json_schema_extra: dict[str, Any] | None = None,
|
|
206
226
|
examples: list[Any] | None = None,
|
|
227
|
+
deprecated: bool | None = None,
|
|
228
|
+
dump: Callable[[Any], Any] | None = None,
|
|
229
|
+
validate: Callable[[Any], Any] | None = None,
|
|
207
230
|
) -> None: ...
|
|
208
231
|
@overload
|
|
209
232
|
def __init__(
|
|
@@ -212,13 +235,14 @@ class Field:
|
|
|
212
235
|
ge: int | float | None = None,
|
|
213
236
|
le: int | float | None = None,
|
|
214
237
|
multiple_of: int | float | None = None,
|
|
215
|
-
default: Any = NODEFAULT,
|
|
216
|
-
default_factory: Callable[[], Any] | None = None,
|
|
217
238
|
alias: str | None = None,
|
|
218
239
|
title: str | None = None,
|
|
219
240
|
description: str | None = None,
|
|
220
241
|
json_schema_extra: dict[str, Any] | None = None,
|
|
221
242
|
examples: list[Any] | None = None,
|
|
243
|
+
deprecated: bool | None = None,
|
|
244
|
+
dump: Callable[[Any], Any] | None = None,
|
|
245
|
+
validate: Callable[[Any], Any] | None = None,
|
|
222
246
|
) -> None: ...
|
|
223
247
|
# Other (string/datetime):
|
|
224
248
|
@overload
|
|
@@ -229,16 +253,15 @@ class Field:
|
|
|
229
253
|
min_length: _NonNegativeInt | None = None,
|
|
230
254
|
max_length: _NonNegativeInt | None = None,
|
|
231
255
|
tz: bool | None = None,
|
|
232
|
-
default: Any = NODEFAULT,
|
|
233
|
-
default_factory: Callable[[], Any] | None = None,
|
|
234
256
|
alias: str | None = None,
|
|
235
257
|
title: str | None = None,
|
|
236
258
|
description: str | None = None,
|
|
237
259
|
json_schema_extra: dict[str, Any] | None = None,
|
|
238
260
|
examples: list[Any] | None = None,
|
|
261
|
+
deprecated: bool | None = None,
|
|
262
|
+
dump: Callable[[Any], Any] | None = None,
|
|
263
|
+
validate: Callable[[Any], Any] | None = None,
|
|
239
264
|
) -> None: ...
|
|
240
|
-
default: Final[Any]
|
|
241
|
-
default_factory: Final[Callable[[], Any] | None]
|
|
242
265
|
alias: Final[str | None]
|
|
243
266
|
gt: Final[int | float | None]
|
|
244
267
|
ge: Final[int | float | None]
|
|
@@ -252,28 +275,15 @@ class Field:
|
|
|
252
275
|
title: Final[str | None]
|
|
253
276
|
description: Final[str | None]
|
|
254
277
|
examples: Final[list[Any] | None]
|
|
278
|
+
deprecated: Final[bool | None]
|
|
255
279
|
json_schema_extra: Final[dict[str, Any] | None]
|
|
280
|
+
dump: Final[Callable[[Any], Any] | None]
|
|
281
|
+
validate: Final[Callable[[Any], Any] | None]
|
|
256
282
|
def __rich_repr__(self) -> list[tuple[str, Any]]: ...
|
|
257
283
|
|
|
258
|
-
class StructConfig:
|
|
259
|
-
frozen: bool
|
|
260
|
-
eq: bool
|
|
261
|
-
order: bool
|
|
262
|
-
array_like: bool
|
|
263
|
-
gc: bool
|
|
264
|
-
repr_omit_defaults: bool
|
|
265
|
-
omit_defaults: bool
|
|
266
|
-
forbid_unknown_fields: bool
|
|
267
|
-
validate_on_init: bool
|
|
268
|
-
weakref: bool
|
|
269
|
-
dict: bool
|
|
270
|
-
cache_hash: bool
|
|
271
|
-
tag: str | int | None
|
|
272
|
-
tag_field: str | None
|
|
273
|
-
|
|
274
284
|
class FieldInfo(Struct):
|
|
275
285
|
name: str
|
|
276
|
-
|
|
286
|
+
alias: str
|
|
277
287
|
type: Any
|
|
278
288
|
default: Any = NODEFAULT
|
|
279
289
|
default_factory: Any = NODEFAULT
|
|
@@ -308,13 +318,11 @@ class StructAdapter:
|
|
|
308
318
|
buf: str | Buffer,
|
|
309
319
|
*,
|
|
310
320
|
strict: bool = True,
|
|
311
|
-
dec_hook: Callable[[type[Any], Any], Any] | None = None,
|
|
312
321
|
) -> Any: ...
|
|
313
322
|
def struct_dump_json(
|
|
314
323
|
self,
|
|
315
324
|
obj: Any,
|
|
316
325
|
*,
|
|
317
|
-
enc_hook: Callable[[Any], Any] | None = None,
|
|
318
326
|
decimal_format: Literal["string", "number"]
|
|
319
327
|
| Callable[[Any], Any]
|
|
320
328
|
| None = None,
|
|
@@ -326,22 +334,17 @@ class StructAdapter:
|
|
|
326
334
|
obj: Any,
|
|
327
335
|
*,
|
|
328
336
|
strict: bool = True,
|
|
329
|
-
dec_hook: Callable[[type[Any], Any], Any] | None = None,
|
|
330
337
|
from_attributes: bool = False,
|
|
331
338
|
) -> Any: ...
|
|
332
339
|
def struct_dump(
|
|
333
340
|
self,
|
|
334
341
|
obj: Any,
|
|
335
342
|
*,
|
|
336
|
-
enc_hook: Callable[[Any], Any] | None = None,
|
|
337
343
|
sort_keys: bool = False,
|
|
338
344
|
str_keys: bool = False,
|
|
339
345
|
builtin_types: Iterable[type] | None = None,
|
|
340
346
|
) -> Any: ...
|
|
341
347
|
|
|
342
|
-
class StrAdapter:
|
|
343
|
-
def __new__(cls, type: type[Any]) -> type[str]: ...
|
|
344
|
-
|
|
345
348
|
class EncodeError(ValueError): ...
|
|
346
349
|
class DecodeError(ValueError): ...
|
|
347
350
|
class ValidationError(ValueError): ...
|