Skip to content

Support Base.get #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
fail-fast: false
matrix:
version:
- '1.0'
- '1.6'
- '1'
- 'nightly'
Expand Down
12 changes: 2 additions & 10 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
name = "PropDicts"
uuid = "4dc08600-4268-439e-8673-d706fafbb426"
version = "0.2.2"
version = "0.2.3"

[deps]
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"

[compat]
JSON = "0.21"
julia = "1"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "Documenter", "Test"]
julia = "1.6"
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"

[compat]
Documenter = "~0.26"
Documenter = "1"
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ makedocs(
],
doctest = ("fixdoctests" in ARGS) ? :fix : true,
linkcheck = ("linkcheck" in ARGS),
strict = !("nonstrict" in ARGS),
warnonly = ("nonstrict" in ARGS),
)

deploydocs(
Expand Down
4 changes: 4 additions & 0 deletions src/propdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ function Base.getindex(p::PropDict, key)
end
end

Base.get(p::PropDict, key, default) = get(_dict(p), key, default)

Base.get!(p::PropDict, key, default) = get!(_dict(p), key, default)

Base.setindex!(p::PropDict, value, key) = setindex!(_dict(p), _convert_value(value), key)
Expand Down Expand Up @@ -310,6 +312,8 @@ MissingProperty(m::MissingProperty) = MissingProperty(_internal_parent(m), _inte

Base.getindex(@nospecialize(m::MissingProperty), @nospecialize(key)) = MissingProperty(m, key)

Base.get(@nospecialize(m::MissingProperty), @nospecialize(key), default) = default

@inline function Base.getproperty(@nospecialize(m::MissingProperty), s::Symbol)
if s == :_internal_parent
getfield(m, :_internal_parent)
Expand Down
4 changes: 4 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3 changes: 1 addition & 2 deletions test/test_aqua.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import PropDicts
Test.@testset "Aqua tests" begin
Aqua.test_all(
PropDicts,
ambiguities = true,
project_toml_formatting = VERSION≥v"1.7"
ambiguities = true
)
end # testset
14 changes: 14 additions & 0 deletions test/test_propdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,18 @@ using Test
@test xa.a.b isa PropDicts.MissingProperty
@test (xa.a.b[33].c = 42) == 42
@test xa.a.b[33].c == 42

pd = PropDict(:a => 42)
@test get(pd, :a, 7) == 42
@test pd.b isa PropDicts.MissingProperty
@test get(pd, :b, 7) == 7
@test pd.b isa PropDicts.MissingProperty
@test get!(pd, :b, 9) == 9
@test !(pd.b isa PropDicts.MissingProperty)
@test pd.b == 9

@test pd.c isa PropDicts.MissingProperty
@test pd.c.d isa PropDicts.MissingProperty
@test get(pd.c, :d, 5) == 5
@test pd.c isa PropDicts.MissingProperty
end