You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#91 fixed an issue related to resolving the names of custom types. However, this only seems to work when the custom types are defined within separate packages, as in the case of the example in the README file.
Consider the following script that generates data.bson
using BSON
include("BModule.jl")
using .BModule
x = BStruct(1)
bson("data.bson", Dict(:x=>x))
with BModule.jl being
module BModule
export BStruct
struct BStruct
b
end
end
If I start a new Julia session and want to read data.bson from a module (without running the code above), e.g., I only run the following in REPL
module CModule
using BSON
include("BModule.jl")
using .BModule
x = BSON.load("data.bson", @__MODULE__)
end
I get an error message that BModule is not defined
The issue seems to be related to the fact that Main is part of the name of the custom type (Main.BModule.BStruct in this case) for locally defined custom types, but it is not part of the names of types defined within packages. #91 does not seem to take that into account.
For my example above, I found two potential workarounds: 1. load BModule in Main from where I have generated data.bson, or 2. redefine resolve() to make sure that the function is looking in the correct namespace, e.g.,
module CModule
using BSON
include("BModule.jl")
using .BModule
function BSON.resolve(fs, init)
if first(fs) == "Main"
fs = fs[2:end]
end
reduce((m, f) -> getfield(m, Symbol(f)), fs; init = init)
end
x = BSON.load("data.bson", @__MODULE__)
end
Solution 1 does not really fix the problem and can become cumbersome if the BSON file was also generated within a module and not in Main. Solution 2 is a bit of a hack, but I hope it provides a starting point for people more knowledgeable than me.
The text was updated successfully, but these errors were encountered:
#91 fixed an issue related to resolving the names of custom types. However, this only seems to work when the custom types are defined within separate packages, as in the case of the example in the README file.
Consider the following script that generates
data.bson
with
BModule.jl
beingIf I start a new Julia session and want to read
data.bson
from a module (without running the code above), e.g., I only run the following in REPLI get an error message that BModule is not defined
The issue seems to be related to the fact that
Main
is part of the name of the custom type (Main.BModule.BStruct
in this case) for locally defined custom types, but it is not part of the names of types defined within packages. #91 does not seem to take that into account.For my example above, I found two potential workarounds: 1. load
BModule
inMain
from where I have generateddata.bson
, or 2. redefine resolve() to make sure that the function is looking in the correct namespace, e.g.,Solution 1 does not really fix the problem and can become cumbersome if the BSON file was also generated within a module and not in
Main
. Solution 2 is a bit of a hack, but I hope it provides a starting point for people more knowledgeable than me.The text was updated successfully, but these errors were encountered: