Skip to content

Commit 5d2bc60

Browse files
authored
Merge pull request #1205 from smortex/to_python-nil
Fix serialization of undef in to_python()
2 parents d64f081 + caaac4f commit 5d2bc60

File tree

4 files changed

+3
-4
lines changed

4 files changed

+3
-4
lines changed

lib/puppet/functions/to_python.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def to_python(object)
2828
case object
2929
when true then 'True'
3030
when false then 'False'
31-
when :undef then 'None'
31+
when nil then 'None'
3232
when Array then "[#{object.map { |x| to_python(x) }.join(', ')}]"
3333
when Hash then "{#{object.map { |k, v| "#{to_python(k)}: #{to_python(v)}" }.join(', ')}}"
3434
else object.inspect

lib/puppet/functions/to_ruby.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
# The String representation of the object
2727
def to_ruby(object)
2828
case object
29-
when :undef then 'nil'
3029
when Array then "[#{object.map { |x| to_ruby(x) }.join(', ')}]"
3130
when Hash then "{#{object.map { |k, v| "#{to_ruby(k)} => #{to_ruby(v)}" }.join(', ')}}"
3231
else object.inspect

spec/functions/to_python_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
describe 'to_python' do
66
it { is_expected.not_to eq(nil) }
77
it { is_expected.to run.with_params('').and_return('""') }
8-
it { is_expected.to run.with_params(:undef).and_return('None') }
8+
it { is_expected.to run.with_params(nil).and_return('None') }
99
it { is_expected.to run.with_params(true).and_return('True') }
1010
it { is_expected.to run.with_params(false).and_return('False') }
1111
it { is_expected.to run.with_params('one').and_return('"one"') }

spec/functions/to_ruby_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
describe 'to_ruby' do
66
it { is_expected.not_to eq(nil) }
77
it { is_expected.to run.with_params('').and_return('""') }
8-
it { is_expected.to run.with_params(:undef).and_return('nil') }
8+
it { is_expected.to run.with_params(nil).and_return('nil') }
99
it { is_expected.to run.with_params(true).and_return('true') }
1010
it { is_expected.to run.with_params('one').and_return('"one"') }
1111
it { is_expected.to run.with_params(42).and_return('42') }

0 commit comments

Comments
 (0)