structtype 0.5.0__tar.gz → 0.7.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.
Files changed (57) hide show
  1. {structtype-0.5.0 → structtype-0.7.0}/AGENTS.md +7 -6
  2. {structtype-0.5.0 → structtype-0.7.0}/Makefile +17 -5
  3. {structtype-0.5.0/src/structtype.egg-info → structtype-0.7.0}/PKG-INFO +13 -4
  4. {structtype-0.5.0 → structtype-0.7.0}/README.md +8 -1
  5. {structtype-0.5.0 → structtype-0.7.0}/pyproject.toml +21 -27
  6. structtype-0.7.0/src/structtype/__init__.py +56 -0
  7. {structtype-0.5.0 → structtype-0.7.0}/src/structtype/__init__.pyi +90 -102
  8. {structtype-0.5.0 → structtype-0.7.0}/src/structtype/_adapter.py +16 -46
  9. {structtype-0.5.0 → structtype-0.7.0}/src/structtype/_core.c +2827 -1101
  10. {structtype-0.5.0 → structtype-0.7.0}/src/structtype/_inspect.py +60 -51
  11. {structtype-0.5.0 → structtype-0.7.0}/src/structtype/_json_schema.py +17 -14
  12. {structtype-0.5.0 → structtype-0.7.0}/src/structtype/_utils.py +23 -21
  13. {structtype-0.5.0 → structtype-0.7.0}/src/structtype/_version.py +2 -2
  14. {structtype-0.5.0 → structtype-0.7.0/src/structtype.egg-info}/PKG-INFO +13 -4
  15. {structtype-0.5.0 → structtype-0.7.0}/src/structtype.egg-info/SOURCES.txt +8 -1
  16. {structtype-0.5.0 → structtype-0.7.0}/tests/test_adapter.py +125 -11
  17. structtype-0.7.0/tests/test_annotations.py +1627 -0
  18. structtype-0.7.0/tests/test_attrs.py +52 -0
  19. {structtype-0.5.0 → structtype-0.7.0}/tests/test_check.py +91 -5
  20. {structtype-0.5.0 → structtype-0.7.0}/tests/test_constraints.py +220 -146
  21. {structtype-0.5.0 → structtype-0.7.0}/tests/test_free_threading.py +45 -0
  22. {structtype-0.5.0 → structtype-0.7.0}/tests/test_inspect.py +66 -28
  23. {structtype-0.5.0 → structtype-0.7.0}/tests/test_json.py +65 -330
  24. {structtype-0.5.0 → structtype-0.7.0}/tests/test_memory.py +0 -20
  25. {structtype-0.5.0 → structtype-0.7.0}/tests/test_pydantic.py +33 -0
  26. {structtype-0.5.0 → structtype-0.7.0}/tests/test_schema.py +58 -16
  27. {structtype-0.5.0 → structtype-0.7.0}/tests/test_struct.py +71 -181
  28. {structtype-0.5.0 → structtype-0.7.0}/tests/test_struct_meta.py +1 -1
  29. structtype-0.7.0/tests/test_typecheck.py +51 -0
  30. structtype-0.7.0/tests/typecheck/api.py +62 -0
  31. structtype-0.7.0/tests/typecheck/basic.py +63 -0
  32. structtype-0.7.0/tests/typecheck/fields.py +56 -0
  33. structtype-0.7.0/tests/typecheck/types.py +100 -0
  34. {structtype-0.5.0 → structtype-0.7.0}/uv.lock +169 -167
  35. structtype-0.5.0/src/structtype/__init__.py +0 -19
  36. {structtype-0.5.0 → structtype-0.7.0}/.opencode/opencode.json +0 -0
  37. {structtype-0.5.0 → structtype-0.7.0}/.opencode/plugins/graphify.js +0 -0
  38. {structtype-0.5.0 → structtype-0.7.0}/LICENSE +0 -0
  39. {structtype-0.5.0 → structtype-0.7.0}/MANIFEST.in +0 -0
  40. {structtype-0.5.0 → structtype-0.7.0}/setup.cfg +0 -0
  41. {structtype-0.5.0 → structtype-0.7.0}/setup.py +0 -0
  42. {structtype-0.5.0 → structtype-0.7.0}/src/structtype/atof.h +0 -0
  43. {structtype-0.5.0 → structtype-0.7.0}/src/structtype/atof_consts.h +0 -0
  44. {structtype-0.5.0 → structtype-0.7.0}/src/structtype/common.h +0 -0
  45. {structtype-0.5.0 → structtype-0.7.0}/src/structtype/itoa.h +0 -0
  46. {structtype-0.5.0 → structtype-0.7.0}/src/structtype/py.typed +0 -0
  47. {structtype-0.5.0 → structtype-0.7.0}/src/structtype/ryu.h +0 -0
  48. {structtype-0.5.0 → structtype-0.7.0}/src/structtype.egg-info/dependency_links.txt +0 -0
  49. {structtype-0.5.0 → structtype-0.7.0}/src/structtype.egg-info/top_level.txt +0 -0
  50. {structtype-0.5.0 → structtype-0.7.0}/tests/__init__.py +0 -0
  51. {structtype-0.5.0 → structtype-0.7.0}/tests/conftest.py +0 -0
  52. {structtype-0.5.0 → structtype-0.7.0}/tests/test_JSONTestSuite.py +0 -0
  53. {structtype-0.5.0 → structtype-0.7.0}/tests/test_cpylint.py +0 -0
  54. {structtype-0.5.0 → structtype-0.7.0}/tests/test_msgspec.py +0 -0
  55. {structtype-0.5.0 → structtype-0.7.0}/tests/test_raw.py +0 -0
  56. {structtype-0.5.0 → structtype-0.7.0}/tests/test_utils.py +0 -0
  57. {structtype-0.5.0 → structtype-0.7.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`, ~20K lines).
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(*, enc_hook=None, decimal_format=None, uuid_format=None, order=None)` — serialize to JSON bytes
51
- - `obj.struct_dump()` — convert to built-in Python types (uses `encode_name` for keys)
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, dec_hook=None)` — deserialize from JSON
54
- - `cls.struct_validate(obj, *, strict=True, from_attributes=False, dec_hook=None)` — convert built-in types to struct
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-lf` reinstalls the C extension before running (last-failed first)
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
 
@@ -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
- .PHONY: test-all
38
- test-all: ## Run tests in all supporte Python versions
39
- for py_v in $(PY_VERSIONS); do \
40
- uv run --isolated --reinstall-package structtype -p $$py_v pytest; \
41
- done
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.5.0
3
+ Version: 0.7.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.com/tds333/structtype
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
- Fast Struct type with validation + JSON serialization for Python.
28
+ [![PyPI version](https://img.shields.io/pypi/v/structtype)](https://pypi.org/project/structtype/)
29
+ [![Python versions](https://img.shields.io/pypi/pyversions/structtype)](https://pypi.org/project/structtype/)
30
+ [![Build status](https://img.shields.io/github/actions/workflow/status/tds333/structtype/build.yml?branch=main)](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
@@ -77,8 +83,11 @@ structtype is as fast as msgspec and about 3-5x faster than pydantic. See the
77
83
 
78
84
  ## Links
79
85
 
86
+ - [Documentation](https://tds333.github.io/structtype/)
80
87
  - [Changelog](https://tds333.github.io/structtype/changelog.html)
88
+ - [PyPI](https://pypi.org/project/structtype/)
81
89
  - [Source code](https://github.com/tds333/structtype)
90
+ - [Issue tracker](https://github.com/tds333/structtype/issues)
82
91
 
83
92
  ## License
84
93
 
@@ -1,6 +1,10 @@
1
1
  # structtype
2
2
 
3
- Fast Struct type with validation + JSON serialization for Python.
3
+ [![PyPI version](https://img.shields.io/pypi/v/structtype)](https://pypi.org/project/structtype/)
4
+ [![Python versions](https://img.shields.io/pypi/pyversions/structtype)](https://pypi.org/project/structtype/)
5
+ [![Build status](https://img.shields.io/github/actions/workflow/status/tds333/structtype/build.yml?branch=main)](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
@@ -54,8 +58,11 @@ structtype is as fast as msgspec and about 3-5x faster than pydantic. See the
54
58
 
55
59
  ## Links
56
60
 
61
+ - [Documentation](https://tds333.github.io/structtype/)
57
62
  - [Changelog](https://tds333.github.io/structtype/changelog.html)
63
+ - [PyPI](https://pypi.org/project/structtype/)
58
64
  - [Source code](https://github.com/tds333/structtype)
65
+ - [Issue tracker](https://github.com/tds333/structtype/issues)
59
66
 
60
67
  ## License
61
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
- "LICENSE",
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.com/tds333/structtype"
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.15'",
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,56 @@
1
+ from ._adapter import StructAdapter
2
+ from ._core import ( # type: ignore
3
+ ALL_BUILTIN_TYPES,
4
+ NODEFAULT,
5
+ UNSET,
6
+ BytesValidator,
7
+ CollectionValidator,
8
+ DecodeError,
9
+ EncodeError,
10
+ Factory,
11
+ Field,
12
+ NumericValidator,
13
+ Raw,
14
+ Serializer,
15
+ Struct,
16
+ StructConfig,
17
+ StructMeta,
18
+ StrValidator,
19
+ TimezoneValidator,
20
+ UnsetType,
21
+ ValidationError,
22
+ Validator,
23
+ )
24
+ from ._inspect import FieldInfo, fields
25
+ from ._json_schema import json_schema, json_schema_components, json_schema_dump
26
+ from ._version import __version__
27
+
28
+ __all__ = [
29
+ "ALL_BUILTIN_TYPES",
30
+ "NODEFAULT",
31
+ "UNSET",
32
+ "BytesValidator",
33
+ "CollectionValidator",
34
+ "DecodeError",
35
+ "EncodeError",
36
+ "Factory",
37
+ "Field",
38
+ "FieldInfo",
39
+ "NumericValidator",
40
+ "Raw",
41
+ "Serializer",
42
+ "StrValidator",
43
+ "Struct",
44
+ "StructAdapter",
45
+ "StructConfig",
46
+ "StructMeta",
47
+ "TimezoneValidator",
48
+ "UnsetType",
49
+ "ValidationError",
50
+ "Validator",
51
+ "__version__",
52
+ "fields",
53
+ "json_schema",
54
+ "json_schema_components",
55
+ "json_schema_dump",
56
+ ]
@@ -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 Any, ClassVar, Final, Literal, TypeAlias, TypeVar, final, overload
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
- from . import StructConfig
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
- __struct_encode_fields__: ClassVar[tuple[str, ...]]
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
- __struct_encode_fields__: ClassVar[tuple[str, ...]]
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,
@@ -126,19 +145,19 @@ class Struct(metaclass=StructMeta):
126
145
  def struct_validate_self(self) -> None: ...
127
146
  @classmethod
128
147
  def struct_validate_json(
129
- cls: type[_T],
148
+ cls,
130
149
  buf: str | Buffer,
131
150
  *,
132
151
  strict: bool = True,
133
- ) -> _T: ...
152
+ ) -> Self: ...
134
153
  @classmethod
135
154
  def struct_validate(
136
- cls: type[_T],
155
+ cls,
137
156
  obj: Any,
138
157
  *,
139
158
  strict: bool = True,
140
159
  from_attributes: bool = False,
141
- ) -> _T: ...
160
+ ) -> Self: ...
142
161
 
143
162
  # Lie and say `Raw` is a subclass of `bytes`, so mypy will accept it in most
144
163
  # places where an object that implements the buffer protocol is valid
@@ -155,132 +174,104 @@ _NonNegativeInt: TypeAlias = int
155
174
 
156
175
  @final
157
176
  class Factory:
158
- def __init__(self, factory: Callable[[], Any]) -> None: ...
177
+ def __new__(cls, factory: Callable[[], Any]) -> Any: ...
159
178
  factory: Final[Callable[[], Any]]
160
179
 
161
180
  @final
162
181
  class Field:
163
- # Numeric:
164
- @overload
165
182
  def __init__(
166
183
  self,
167
184
  *,
168
- gt: int | float | None = None,
169
- lt: int | float | None = None,
170
- multiple_of: int | float | None = None,
171
185
  alias: str | None = None,
172
186
  title: str | None = None,
173
187
  description: str | None = None,
174
188
  json_schema_extra: dict[str, Any] | None = None,
175
189
  examples: list[Any] | None = None,
176
190
  deprecated: bool | None = None,
177
- dump: Callable[[Any], Any] | None = None,
178
- validate: Callable[[Any], Any] | None = None,
179
191
  ) -> None: ...
180
- @overload
192
+ alias: Final[str | None]
193
+ title: Final[str | None]
194
+ description: Final[str | None]
195
+ examples: Final[list[Any] | None]
196
+ deprecated: Final[bool | None]
197
+ json_schema_extra: Final[dict[str, Any] | None]
198
+ def __rich_repr__(self) -> list[tuple[str, Any]]: ...
199
+
200
+ @final
201
+ class Serializer:
181
202
  def __init__(
182
203
  self,
183
204
  *,
184
- gt: int | float | None = None,
185
- le: int | float | None = None,
186
- multiple_of: int | float | None = None,
187
- alias: str | None = None,
188
- title: str | None = None,
189
- description: str | None = None,
190
- json_schema_extra: dict[str, Any] | None = None,
191
- examples: list[Any] | None = None,
192
- deprecated: bool | None = None,
205
+ load: Callable[[Any], Any] | None = None,
193
206
  dump: Callable[[Any], Any] | None = None,
194
- validate: Callable[[Any], Any] | None = None,
195
207
  ) -> None: ...
196
- @overload
208
+ load: Final[Callable[[Any], Any] | None]
209
+ dump: Final[Callable[[Any], Any] | None]
210
+
211
+ class Validator:
212
+ def __init__(self, fn: Callable[[Any], Any] | None = None) -> None: ...
213
+ def __call__(self, value: Any) -> None: ...
214
+
215
+ @final
216
+ class NumericValidator(Validator):
197
217
  def __init__(
198
218
  self,
199
219
  *,
220
+ gt: int | float | None = None,
200
221
  ge: int | float | None = None,
201
222
  lt: int | float | None = None,
223
+ le: int | float | None = None,
202
224
  multiple_of: int | float | None = None,
203
- alias: str | None = None,
204
- title: str | None = None,
205
- description: str | None = None,
206
- json_schema_extra: dict[str, Any] | None = None,
207
- examples: list[Any] | None = None,
208
- deprecated: bool | None = None,
209
- dump: Callable[[Any], Any] | None = None,
210
- validate: Callable[[Any], Any] | None = None,
211
225
  ) -> None: ...
212
- @overload
226
+ gt: Final[int | float | None]
227
+ ge: Final[int | float | None]
228
+ lt: Final[int | float | None]
229
+ le: Final[int | float | None]
230
+ multiple_of: Final[int | float | None]
231
+
232
+ @final
233
+ class StrValidator(Validator):
213
234
  def __init__(
214
235
  self,
215
236
  *,
216
- ge: int | float | None = None,
217
- le: int | float | None = None,
218
- multiple_of: int | float | None = None,
219
- alias: str | None = None,
220
- title: str | None = None,
221
- description: str | None = None,
222
- json_schema_extra: dict[str, Any] | None = None,
223
- examples: list[Any] | None = None,
224
- deprecated: bool | None = None,
225
- dump: Callable[[Any], Any] | None = None,
226
- validate: Callable[[Any], Any] | None = None,
237
+ pattern: str | None = None,
238
+ min_length: _NonNegativeInt | None = None,
239
+ max_length: _NonNegativeInt | None = None,
227
240
  ) -> None: ...
228
- # Other (string/datetime):
229
- @overload
241
+ pattern: Final[str | None]
242
+ min_length: Final[int | None]
243
+ max_length: Final[int | None]
244
+
245
+ @final
246
+ class BytesValidator(Validator):
230
247
  def __init__(
231
248
  self,
232
249
  *,
233
- pattern: str | None = None,
234
250
  min_length: _NonNegativeInt | None = None,
235
251
  max_length: _NonNegativeInt | None = None,
236
- tz: bool | None = None,
237
- alias: str | None = None,
238
- title: str | None = None,
239
- description: str | None = None,
240
- json_schema_extra: dict[str, Any] | None = None,
241
- examples: list[Any] | None = None,
242
- deprecated: bool | None = None,
243
- dump: Callable[[Any], Any] | None = None,
244
- validate: Callable[[Any], Any] | None = None,
245
252
  ) -> None: ...
246
- alias: Final[str | None]
247
- gt: Final[int | float | None]
248
- ge: Final[int | float | None]
249
- lt: Final[int | float | None]
250
- le: Final[int | float | None]
251
- multiple_of: Final[int | float | None]
252
- pattern: Final[str | None]
253
253
  min_length: Final[int | None]
254
254
  max_length: Final[int | None]
255
- tz: Final[int | None]
256
- title: Final[str | None]
257
- description: Final[str | None]
258
- examples: Final[list[Any] | None]
259
- deprecated: Final[bool | None]
260
- json_schema_extra: Final[dict[str, Any] | None]
261
- dump: Final[Callable[[Any], Any] | None]
262
- validate: Final[Callable[[Any], Any] | None]
263
- def __rich_repr__(self) -> list[tuple[str, Any]]: ...
264
255
 
265
- class StructConfig:
266
- frozen: bool
267
- eq: bool
268
- order: bool
269
- array_like: bool
270
- gc: bool
271
- repr_omit_defaults: bool
272
- omit_defaults: bool
273
- forbid_unknown_fields: bool
274
- validate_on_init: bool
275
- weakref: bool
276
- dict: bool
277
- cache_hash: bool
278
- tag: str | int | None
279
- tag_field: str | None
256
+ @final
257
+ class CollectionValidator(Validator):
258
+ def __init__(
259
+ self,
260
+ *,
261
+ min_length: _NonNegativeInt | None = None,
262
+ max_length: _NonNegativeInt | None = None,
263
+ ) -> None: ...
264
+ min_length: Final[int | None]
265
+ max_length: Final[int | None]
266
+
267
+ @final
268
+ class TimezoneValidator(Validator):
269
+ def __init__(self, *, tz: bool) -> None: ...
270
+ tz: Final[bool]
280
271
 
281
272
  class FieldInfo(Struct):
282
273
  name: str
283
- encode_name: str
274
+ alias: str
284
275
  type: Any
285
276
  default: Any = NODEFAULT
286
277
  default_factory: Any = NODEFAULT
@@ -342,9 +333,6 @@ class StructAdapter:
342
333
  builtin_types: Iterable[type] | None = None,
343
334
  ) -> Any: ...
344
335
 
345
- class StrAdapter:
346
- def __new__(cls, type: type[Any]) -> type[str]: ...
347
-
348
336
  class EncodeError(ValueError): ...
349
337
  class DecodeError(ValueError): ...
350
338
  class ValidationError(ValueError): ...