Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

sometimes dicts are passed to constructors as `Dict{String,Any}`

オープン
#23 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
julia
領域
tooling

調査の方向性

まず Julia MWE を実行し、StructTypes.jl:267 のコンストラクター呼び出しを structs.jl:342 にある JSON3 の読み取りパスと併せて追跡します。Outer と Inner が辞書キーをどのように受け取るかを比較し、報告されたネストされた構築のケースで、Dict{String,Any} と Dict{Symbol,Any} 用の別々のコンストラクターがもはや必要ないことを確認します。

索引モデルが issue の本文から書いたものです。

説明

I started out thinking this only happened for nested types, but as I set out to make a MWE, I got even more confused. Here it is

using JSON3, StructTypes

struct Inner
    a::Int
end
Inner(dct) = Inner(dct[:a])

StructTypes.StructType(::Type{Inner}) = StructTypes.DictType()

struct Outer
    I::Inner
end
Outer(dct) = Outer(dct[:I])

StructTypes.StructType(::Type{Outer}) = StructTypes.DictType()


json = JSON3.write(Dict(:I=>Dict(:a=>1)))
JSON3.read(json, Outer)

gives me

ERROR: LoadError: KeyError: key :I not found
Stacktrace:
 [1] getindex at ./dict.jl:467 [inlined]
 [2] Outer(::Dict{String,Any}) at /home/expandingman/src/scrap.jl:13 (repeats 2 times)
 [3] #construct#2 at /home/expandingman/.julia/packages/StructTypes/CpLmq/src/StructTypes.jl:267 [in
lined]
 [4] construct at /home/expandingman/.julia/packages/StructTypes/CpLmq/src/StructTypes.jl:267 [inlin
ed]
 [5] read(::StructTypes.DictType, ::Base.CodeUnits{UInt8,String}, ::Int64, ::Int64, ::UInt8, ::Type{
Outer}, ::Type{Symbol}, ::Type{Any}; kw::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),
Tuple{}}}) at /home/expandingman/.julia/packages/JSON3/LtYDK/src/structs.jl:342
 [6] read at /home/expandingman/.julia/packages/JSON3/LtYDK/src/structs.jl:285 [inlined]
 [7] #read#30 at /home/expandingman/.julia/packages/JSON3/LtYDK/src/structs.jl:279 [inlined]
 [8] read at /home/expandingman/.julia/packages/JSON3/LtYDK/src/structs.jl:279 [inlined]
 [9] read(::String, ::Type{Outer}; kw::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tu
ple{}}}) at /home/expandingman/.julia/packages/JSON3/LtYDK/src/structs.jl:34
 [10] read(::String, ::Type{Outer}) at /home/expandingman/.julia/packages/JSON3/LtYDK/src/structs.jl
:33
 [11] top-level scope at /home/expandingman/src/scrap.jl:19
 [12] include(::String) at ./client.jl:457
 [13] top-level scope at REPL[3]:1
in expression starting at /home/expandingman/src/scrap.jl:19

Usually I would hit this kind of error with Inner where it would try to construct from Dict("a"=>1), I don't know why I suddenly have this problem with the outer one.

As a workaround, it seems that right now one has to define constructors for both Dict{String,Any} and Dict{Symbol,Any} which seems wrong.

主要言語
Julia
スター
86
フォーク
21
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

JuliaData/StructTypes.jl のほかの issue

JuliaData/StructTypes.jl の issue をすべて見る

似ている issue

Julia の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。