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
1211from __future__ import annotations
1312
1413import asyncio
15- from collections .abc import Mapping , Sequence
14+ from collections .abc import Mapping
1615from types import ModuleType
1716from typing import Any , Generic , Protocol , TypeVar
1817
@@ -23,143 +22,42 @@ TReader = TypeVar("TReader")
2322TBuilder = TypeVar ("TBuilder" )
2423TInterface = 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
6527class EnumType (Protocol ):
6628 typeId : int
6729
6830class StructType (Protocol ):
6931 typeId : int
70- brand : Brand
7132
7233class 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
10738class 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
15153class 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
16058class 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
16462ModuleType = ModuleType
16563Server = asyncio .Server
0 commit comments