Skip to content

Commit d213f07

Browse files
chore: remove most internal stuff
1 parent 1ff6001 commit d213f07

File tree

2 files changed

+13
-177
lines changed

2 files changed

+13
-177
lines changed

capnp/__init__.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +0,0 @@
1-
"""A python library wrapping the Cap'n Proto C++ library
2-
3-
Example Usage::
4-
5-
import capnp
6-
7-
addressbook = capnp.load('addressbook.capnp')
8-
9-
# Building
10-
addresses = addressbook.AddressBook.newMessage()
11-
people = addresses.init('people', 1)
12-
13-
alice = people[0]
14-
alice.id = 123
15-
alice.name = 'Alice'
16-
alice.email = 'alice@example.com'
17-
alicePhone = alice.init('phones', 1)[0]
18-
alicePhone.type = 'mobile'
19-
20-
f = open('example.bin', 'w')
21-
addresses.write(f)
22-
f.close()
23-
24-
# Reading
25-
f = open('example.bin')
26-
27-
addresses = addressbook.AddressBook.read(f)
28-
29-
for person in addresses.people:
30-
print(person.name, ':', person.email)
31-
for phone in person.phones:
32-
print(phone.type, ':', phone.number)
33-
"""
34-
35-
# flake8: noqa F401 F403 F405
36-
from .version import version as __version__
37-
from .lib.capnp import *
38-
from .lib.capnp import (
39-
_CapabilityClient,
40-
_DynamicCapabilityClient,
41-
_DynamicListBuilder,
42-
_DynamicListReader,
43-
_DynamicOrphan,
44-
_DynamicResizableListBuilder,
45-
_DynamicStructBuilder,
46-
_DynamicStructReader,
47-
_EventLoop,
48-
_InterfaceModule,
49-
_ListSchema,
50-
_MallocMessageBuilder,
51-
_PyCustomMessageBuilder,
52-
_PackedFdMessageReader,
53-
_StreamFdMessageReader,
54-
_StructModule,
55-
_write_message_to_fd,
56-
_write_packed_message_to_fd,
57-
_AsyncIoStream as AsyncIoStream,
58-
_init_capnp_api,
59-
)
60-
61-
_init_capnp_api()
62-
add_import_hook() # enable import hook by default

capnp/_internal.pyi

Lines changed: 13 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
"""Internal types for pycapnp stubs - NOT part of public API.
22
3-
This module contains all internal type definitions including:
4-
- Protocol classes for schema nodes
3+
This module contains internal type definitions including:
4+
- Protocol classes for schema nodes that exist in the pycapnp runtime
55
- TypeVars used in generic types
66
- Helper types for type annotations
7-
- Types from imports (asyncio, ModuleType, etc.)
87
9-
These are imported by __init__.pyi for type annotations but NOT re-exported.
8+
These are imported by lib/capnp.pyi for type annotations but NOT re-exported.
109
"""
1110

1211
from __future__ import annotations
1312

1413
import asyncio
15-
from collections.abc import Mapping, Sequence
14+
from collections.abc import Mapping
1615
from types import ModuleType
1716
from typing import Any, Generic, Protocol, TypeVar
1817

@@ -23,143 +22,42 @@ TReader = TypeVar("TReader")
2322
TBuilder = TypeVar("TBuilder")
2423
TInterface = TypeVar("TInterface")
2524

26-
# Protocol classes for schema introspection
27-
28-
class NestedNode(Protocol):
29-
name: str
30-
id: int
31-
32-
class ParameterNode(Protocol):
33-
name: str
34-
35-
class Enumerant(Protocol):
36-
name: str
37-
38-
class EnumNode(Protocol):
39-
enumerants: Sequence[Enumerant]
40-
41-
class AnyPointerParameter(Protocol):
42-
parameterIndex: int
43-
scopeId: int
44-
45-
class AnyPointerType(Protocol):
46-
def which(self) -> str: ...
47-
parameter: AnyPointerParameter
48-
49-
class BrandBinding(Protocol):
50-
type: TypeReader
51-
52-
class BrandScope(Protocol):
53-
def which(self) -> str: ...
54-
scopeId: int
55-
bind: Sequence[BrandBinding]
56-
57-
class Brand(Protocol):
58-
scopes: Sequence[BrandScope]
59-
60-
class ListElementType(Protocol):
61-
elementType: TypeReader
62-
63-
class ListType(ListElementType, Protocol): ...
25+
# Protocol classes for types imported from capnp runtime
6426

6527
class EnumType(Protocol):
6628
typeId: int
6729

6830
class StructType(Protocol):
6931
typeId: int
70-
brand: Brand
7132

7233
class InterfaceType(Protocol):
7334
typeId: int
7435

75-
class TypeReader(Protocol):
76-
def which(self) -> str: ...
77-
list: ListType
78-
enum: EnumType
79-
struct: StructType
80-
interface: InterfaceType
81-
anyPointer: AnyPointerType
82-
elementType: TypeReader
83-
84-
class SlotNode(Protocol):
85-
type: TypeReader
86-
87-
class FieldNode(Protocol):
88-
name: str
89-
slot: SlotNode
90-
discriminantValue: int
91-
def which(self) -> str: ...
92-
93-
class StructNode(Protocol):
94-
fields: Sequence[FieldNode]
95-
discriminantCount: int
96-
97-
class ConstNode(Protocol):
98-
type: TypeReader
99-
100-
class InterfaceNode(Protocol):
101-
methods: Sequence[InterfaceMethod]
102-
superclasses: Sequence[SuperclassNode]
103-
104-
class SuperclassNode(Protocol):
105-
id: int
36+
class SlotRuntime(Protocol): ...
10637

10738
class SchemaNode(Protocol):
10839
id: int
10940
scopeId: int
11041
displayName: str
11142
displayNamePrefixLength: int
112-
nestedNodes: Sequence[NestedNode]
113-
parameters: Sequence[ParameterNode]
11443
isGeneric: bool
115-
struct: StructNode
116-
enum: EnumNode
117-
const: ConstNode
118-
interface: InterfaceNode
11944
def which(self) -> str: ...
12045

121-
class DefaultValueReader(Protocol):
122-
def as_bool(self) -> bool: ...
123-
def __str__(self) -> str: ...
124-
125-
class StructRuntime(Protocol):
126-
fields_list: Sequence[Any]
127-
128-
class StructSchema(Protocol, Generic[TReader, TBuilder]):
129-
node: SchemaNode
130-
elementType: TypeReader
131-
def as_struct(self) -> StructRuntime: ...
132-
def get_nested(self, name: str) -> StructSchema: ...
46+
class StructSchema(Protocol, Generic[TReader, TBuilder]): ...
13347

134-
class ListSchema(Protocol):
135-
node: SchemaNode
136-
elementType: TypeReader
137-
def as_struct(self) -> StructRuntime: ...
138-
def get_nested(self, name: str) -> StructSchema: ...
48+
# Protocol classes for types that exist in pycapnp runtime but are accessed
49+
# as attributes or return values (not directly imported)
13950

140-
class DynamicListReader(Protocol):
141-
elementType: TypeReader
142-
list: DynamicListReader
143-
144-
class SlotRuntime(Protocol):
145-
type: TypeReader
146-
147-
class InterfaceMethod(Protocol):
148-
param_type: StructSchema
149-
result_type: StructSchema
51+
class DynamicListReader(Protocol): ...
15052

15153
class InterfaceSchema(Protocol):
152-
methods: Mapping[str, InterfaceMethod]
153-
154-
class InterfaceRuntime(Protocol):
155-
schema: InterfaceSchema
54+
methods: Mapping[str, Any]
15655

157-
class CastableBootstrap(Protocol):
158-
def cast_as(self, interface: type[TInterface]) -> TInterface: ...
56+
class ListSchema(Protocol): ...
15957

16058
class StructModule(Protocol, Generic[TReader, TBuilder]):
16159
schema: StructSchema[TReader, TBuilder]
16260

163-
# Re-export commonly used types with underscore prefix for internal use
61+
# Re-export commonly used types
16462
ModuleType = ModuleType
16563
Server = asyncio.Server

0 commit comments

Comments
 (0)