Skip to content

Commit b82459a

Browse files
torfjeldeyebai
andauthored
Removal of redundant backwards compat to_namedtuple_expr (#280)
* improved leftover to_namedtuple_expr, fixing a bug when used with Zygote * bumped patch version Co-authored-by: Hong Ge <[email protected]>
1 parent 309583a commit b82459a

File tree

2 files changed

+6
-33
lines changed

2 files changed

+6
-33
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DynamicPPL"
22
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
3-
version = "0.12.2"
3+
version = "0.12.3"
44

55
[deps]
66
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"

src/utils.jl

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,39 +44,12 @@ function getargs_tilde(expr::Expr)
4444
end
4545
end
4646

47-
############################################
48-
# Julia 1.2 temporary fix - Julia PR 33303 #
49-
############################################
5047
function to_namedtuple_expr(syms, vals=syms)
51-
if length(syms) == 0
52-
nt = :(NamedTuple())
53-
else
54-
nt_type = Expr(
55-
:curly,
56-
:NamedTuple,
57-
Expr(:tuple, QuoteNode.(syms)...),
58-
Expr(:curly, :Tuple, [:(Core.Typeof($x)) for x in vals]...),
59-
)
60-
nt = Expr(:call, :($(DynamicPPL.namedtuple)), nt_type, Expr(:tuple, vals...))
61-
end
62-
return nt
63-
end
64-
65-
if VERSION == v"1.2"
66-
@eval function namedtuple(
67-
::Type{NamedTuple{names,T}}, args::Tuple
68-
) where {names,T<:Tuple}
69-
if length(args) != length(names)
70-
throw(ArgumentError("Wrong number of arguments to named tuple constructor."))
71-
end
72-
# Note T(args) might not return something of type T; e.g.
73-
# Tuple{Type{Float64}}((Float64,)) returns a Tuple{DataType}
74-
return $(Expr(:splatnew, :(NamedTuple{names,T}), :(T(args))))
75-
end
76-
else
77-
function namedtuple(::Type{NamedTuple{names,T}}, args::Tuple) where {names,T<:Tuple}
78-
return NamedTuple{names,T}(args)
79-
end
48+
length(syms) == 0 && return :(NamedTuple())
49+
50+
names_expr = Expr(:tuple, QuoteNode.(syms)...)
51+
vals_expr = Expr(:tuple, vals...)
52+
return :(NamedTuple{$names_expr}($vals_expr))
8053
end
8154

8255
#####################################################

0 commit comments

Comments
 (0)