Skip to content

Commit 1ff6001

Browse files
fix: _ListSchema
1 parent 30b3cf1 commit 1ff6001

File tree

3 files changed

+61
-133
lines changed

3 files changed

+61
-133
lines changed

capnp/__init__.pyi

Lines changed: 42 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,54 @@
11
from __future__ import annotations
22

33
# Import submodules
4-
from capnp import lib as lib
5-
from capnp import version as version
6-
from capnp.lib.capnp import (
7-
# Public classes
8-
AsyncIoStream as AsyncIoStream,
9-
)
4+
from capnp import lib, version
105

11-
# Re-export everything from lib.capnp that's part of the public API
6+
# Import the types module from lib.capnp where it's actually defined
127
from capnp.lib.capnp import (
8+
# Public classes
9+
AsyncIoStream,
1310
# Exception classes
14-
KjException as KjException,
15-
)
16-
from capnp.lib.capnp import (
17-
SchemaLoader as SchemaLoader,
18-
)
19-
from capnp.lib.capnp import (
20-
SchemaParser as SchemaParser,
21-
)
22-
from capnp.lib.capnp import (
23-
TwoPartyClient as TwoPartyClient,
24-
)
25-
from capnp.lib.capnp import (
26-
TwoPartyServer as TwoPartyServer,
27-
)
28-
from capnp.lib.capnp import (
29-
# Internal classes that are re-exported
30-
_CapabilityClient as _CapabilityClient,
31-
)
32-
from capnp.lib.capnp import (
33-
_DynamicCapabilityClient as _DynamicCapabilityClient,
34-
)
35-
from capnp.lib.capnp import (
36-
_DynamicListBuilder as _DynamicListBuilder,
37-
)
38-
from capnp.lib.capnp import (
39-
_DynamicListReader as _DynamicListReader,
40-
)
41-
from capnp.lib.capnp import (
42-
_DynamicOrphan as _DynamicOrphan,
43-
)
44-
from capnp.lib.capnp import (
45-
_DynamicResizableListBuilder as _DynamicResizableListBuilder,
46-
)
47-
from capnp.lib.capnp import (
48-
_DynamicStructBuilder as _DynamicStructBuilder,
49-
)
50-
from capnp.lib.capnp import (
51-
_DynamicStructReader as _DynamicStructReader,
52-
)
53-
from capnp.lib.capnp import (
54-
_EventLoop as _EventLoop,
55-
)
56-
from capnp.lib.capnp import (
57-
_init_capnp_api as _init_capnp_api,
58-
)
59-
from capnp.lib.capnp import (
60-
_InterfaceModule as _InterfaceModule,
61-
)
62-
from capnp.lib.capnp import (
63-
_ListSchema as _ListSchema,
64-
)
65-
from capnp.lib.capnp import (
66-
_MallocMessageBuilder as _MallocMessageBuilder,
67-
)
68-
from capnp.lib.capnp import (
69-
_PackedFdMessageReader as _PackedFdMessageReader,
70-
)
71-
from capnp.lib.capnp import (
72-
_PyCustomMessageBuilder as _PyCustomMessageBuilder,
73-
)
74-
from capnp.lib.capnp import (
75-
_StreamFdMessageReader as _StreamFdMessageReader,
76-
)
77-
from capnp.lib.capnp import (
78-
_StructModule as _StructModule,
79-
)
80-
from capnp.lib.capnp import (
81-
_write_message_to_fd as _write_message_to_fd,
82-
)
83-
from capnp.lib.capnp import (
84-
_write_packed_message_to_fd as _write_packed_message_to_fd,
85-
)
86-
from capnp.lib.capnp import (
11+
KjException,
12+
SchemaLoader,
13+
SchemaParser,
14+
TwoPartyClient,
15+
TwoPartyServer,
16+
# Internal classes and functions that are re-exported
17+
_CapabilityClient,
18+
_DynamicCapabilityClient,
19+
_DynamicListBuilder,
20+
_DynamicListReader,
21+
_DynamicOrphan,
22+
_DynamicResizableListBuilder,
23+
_DynamicStructBuilder,
24+
_DynamicStructReader,
25+
_EventLoop,
26+
_init_capnp_api,
27+
_InterfaceModule,
28+
_ListSchema,
29+
_MallocMessageBuilder,
30+
_PackedFdMessageReader,
31+
_PyCustomMessageBuilder,
32+
_StreamFdMessageReader,
33+
_StructModule,
34+
_write_message_to_fd,
35+
_write_packed_message_to_fd,
8736
# Public functions
88-
add_import_hook as add_import_hook,
89-
)
90-
from capnp.lib.capnp import (
91-
cleanup_global_schema_parser as cleanup_global_schema_parser,
92-
)
93-
from capnp.lib.capnp import (
94-
deregister_all_types as deregister_all_types,
95-
)
96-
from capnp.lib.capnp import (
97-
fill_context as fill_context,
98-
)
99-
from capnp.lib.capnp import (
100-
kj_loop as kj_loop,
101-
)
102-
from capnp.lib.capnp import (
103-
load as load,
104-
)
105-
from capnp.lib.capnp import (
106-
read_multiple_bytes_packed as read_multiple_bytes_packed,
107-
)
108-
from capnp.lib.capnp import (
109-
register_type as register_type,
110-
)
111-
from capnp.lib.capnp import (
112-
remove_import_hook as remove_import_hook,
113-
)
114-
from capnp.lib.capnp import (
115-
run as run,
116-
)
117-
118-
# Import the types module from lib.capnp where it's actually defined
119-
from capnp.lib.capnp import types as types
120-
from capnp.lib.capnp import (
121-
void_task_done_callback as void_task_done_callback,
37+
add_import_hook,
38+
cleanup_global_schema_parser,
39+
deregister_all_types,
40+
fill_context,
41+
kj_loop,
42+
load,
43+
read_multiple_bytes_packed,
44+
register_type,
45+
remove_import_hook,
46+
run,
47+
types,
48+
void_task_done_callback,
12249
)
12350

51+
# Re-export everything from lib.capnp that's part of the public API
12452
# Version string
12553
from capnp.version import version as __version__
12654

capnp/lib/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
from __future__ import annotations
44

55
# The lib package just contains the capnp submodule
6-
from capnp.lib import capnp as capnp
6+
from capnp.lib import capnp
77

88
__all__ = ["capnp"]

capnp/lib/capnp.pyi

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ from capnp._internal import (
2929
from capnp._internal import (
3030
SlotRuntime as _SlotRuntime,
3131
)
32-
from capnp._internal import (
33-
StructRuntime as _StructRuntime,
34-
)
3532
from capnp._internal import (
3633
StructSchema as _StructSchema,
3734
)
@@ -45,9 +42,6 @@ from capnp._internal import (
4542
TInterface,
4643
TReader,
4744
)
48-
from capnp._internal import (
49-
TypeReader as _TypeReader,
50-
)
5145

5246
class KjException(Exception):
5347
"""Exception raised by Cap'n Proto operations.
@@ -634,14 +628,24 @@ class _ListSchema:
634628
Can be instantiated to create list schemas for different element types.
635629
"""
636630

637-
elementType: (
638-
_TypeReader
639-
| _StructSchema
640-
| _EnumSchema
641-
| _InterfaceSchema
642-
| _ListSchema
643-
| _SchemaType
644-
)
631+
@property
632+
def elementType(
633+
self,
634+
) -> _StructSchema | _EnumSchema | _InterfaceSchema | _ListSchema:
635+
"""The schema of the element type of this list.
636+
637+
Returns:
638+
Schema of the list element type:
639+
- _StructSchema for struct elements
640+
- _EnumSchema for enum elements
641+
- _InterfaceSchema for interface elements
642+
- _ListSchema for nested list elements
643+
644+
Raises:
645+
KjException: When the element type is a primitive type (Int32, Text, Bool, etc.)
646+
with message "Schema type is unknown"
647+
"""
648+
...
645649

646650
def __init__(
647651
self,
@@ -651,7 +655,6 @@ class _ListSchema:
651655
| _InterfaceSchema
652656
| _ListSchema
653657
| _SchemaType
654-
| _StructSchema
655658
| Any
656659
| None
657660
) = None,
@@ -670,9 +673,6 @@ class _ListSchema:
670673
"""
671674
...
672675

673-
def as_struct(self) -> _StructRuntime: ...
674-
def get_nested(self, name: str) -> _StructSchema: ...
675-
676676
# RPC Request/Response Types
677677
class _Request(_DynamicStructBuilder, Protocol):
678678
"""RPC request builder.

0 commit comments

Comments
 (0)