Skip to content

Commit 015d28c

Browse files
committed
Restrict patch to NamedTuple
1 parent f3cf74a commit 015d28c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
ConstructionBase is a very lightwight package, that provides primitive functions for construction of objects:
99
```julia
10-
setproperties(obj::MyType, patch)
10+
setproperties(obj::MyType, patch::NamedTuple)
1111
constructorof(MyType)
1212
```
1313
These functions can be overloaded and doing so provides interoperability the following packages:

src/ConstructionBase.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function assert_hasfields(T, fnames)
7272
end
7373

7474
"""
75-
setproperties(obj, patch)
75+
setproperties(obj, patch::NamedTuple)
7676
7777
Return a copy of `obj` with attributes updates accoring to `patch`.
7878
@@ -111,15 +111,15 @@ S("A", 2, "cc")
111111
# Overloading
112112
113113
**WARNING** The signature `setproperties(obj::MyType; kw...)` should never be overloaded.
114-
Instead `setproperties(obj::MyType, patch)` should be overloaded.
114+
Instead `setproperties(obj::MyType, patch::NamedTuple)` should be overloaded.
115115
"""
116116
function setproperties end
117117

118118
function setproperties(obj; kw...)
119119
setproperties(obj, (;kw...))
120120
end
121121

122-
@generated function setproperties(obj, patch)
122+
@generated function setproperties(obj, patch::NamedTuple)
123123
assert_hasfields(obj, fieldnames(patch))
124124
args = map(fieldnames(obj)) do fn
125125
if fn in fieldnames(patch)
@@ -134,7 +134,7 @@ end
134134
)
135135
end
136136

137-
@generated function setproperties(obj::NamedTuple, patch)
137+
@generated function setproperties(obj::NamedTuple, patch::NamedTuple)
138138
# this function is only generated to force the following check
139139
# at compile time
140140
assert_hasfields(obj, fieldnames(patch))

0 commit comments

Comments
 (0)