Imported type is not visible when using pycapnp.
I have 2 files, first is vec1.capnp
@0xf449cc59f43990cf;
struct Vec {
x @0: Float64;
}
and the 2nd is vec2.capnp
@0xf449cc59f43990c0;
using Vec = import "vec1.capnp".Vec;
struct Vec2 {
x @0: Float64;
y @1: Vec;
}
When creating a new message with
import capnp
capnp.remove_import_hook()
schema = capnp.load('vec2.capnp')
instance = schema.Vec2.new_message()
print(instance)
the result is
(x = 0)
y is missing. Vec is also missing when listing all types of the schema.
The attribute y is there, in the instance, and you can find it in the instance class if calling dir(instance). Also it will appear in the print as soon as you'll call y at least once. I guess capnp is doing lazy initialisation for custom types, thus you won't see attribute until you'll try to access it first.
import capnp
capnp.remove_import_hook()
schema = capnp.load('vec2.capnp')
instance = schema.Vec2.new_message()
instance.y
print(instance)
# Outputs: (x = 0, y = (x = 0))
or
instance = schema.Vec2.new_message(y = {})
print(instance)
# Outputs: (x = 0, y = (x = 0))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With