-
Notifications
You must be signed in to change notification settings - Fork 580
(MODULES-1473) Deprecate type() function for new parser #382
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
Conversation
there is no unit test for the type_of function |
|
||
module Puppet::Parser::Functions | ||
newfunction(:type_of, :type => :rvalue, :doc => <<-EOS | ||
Returns the type when passed a variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Returns the type of a value" (it is not limited to variables, it can be used on a literal as well as on types; e.g. 'any value').
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True.
I can't seem to get the unit test to work at all :(. It can't load the function, and digging through the puppet source code doesn't seem to highlight anything. Help @hlindberg or @cyberious ? |
Tests pushed. Someone labeled this "backwards incompatible" though it is backwards compat. |
#! /usr/bin/env ruby -S rspec | ||
|
||
require 'spec_helper' | ||
require 'puppet/pops' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be wrapped within the ENV['FUTURE_PARSER']
# @example how to compare values' types | ||
# # compare the types of two values | ||
# if type_of($first_value) != type_of($second_value) { fail("first_value and second_value are different types") } | ||
# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can add this as well:
@example how to compare against a type
unless type_of($first_value) <= Numeric { fail("first_value must be Numeric") }
unless type_of{$first_value) <= Collection[1] { fail("first_value must be an Array or Hash, and contain at least one element") }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
a34db4e
to
a275635
Compare
@@ -464,7 +464,11 @@ manifests as a valid password attribute. *Type*: rvalue | |||
* `to_bytes`: Converts the argument into bytes, for example 4 kB becomes 4096. | |||
Takes a single string value as an argument. *Type*: rvalue | |||
|
|||
* `type`: Returns the type when passed a variable. Type can be a string, array, hash, float, integer, or boolean. *Type*: rvalue | |||
* `type3x`: Returns a string description of the type when passed a variable. Type can be a string, array, hash, float, integer, or boolean. This function will be removed when puppet 3 support is dropped and the new type system may be used. *Type*: rvalue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same change here as I commented on in an outdated diff, it is not just "a variable", it is any expression e.g. type3x(1+2)
* `type3x`: Returns a string description of the type when passed a variable. Type can be a string, array, hash, float, integer, or boolean. This function will be removed when puppet 3 support is dropped and the new type system may be used. *Type*: rvalue | ||
|
||
* `type_of`: Returns the literal type when passed a variable. Requires the new | ||
parser. The output is meant for human use; for programatic inspection of types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it is true that interpolating the resulting type (or passing it to notice) will produce a string representation of the type, it is also very useful to get the type of something and using that result multiple times (as opposed to doing multiple =~ where the type has to be inferred each time.) Note that $value =~ Numeric
is the same as doing type_of($value) <= Numeric
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I like the look of =~ Numeric
over <= Numeric
. And yeah, I see your point, now. I wrote that before I knew what it was for.
I think my last comment was made as you pushed new changes... |
|
||
* `type_of`: Returns the literal type when passed a value. Requires the new | ||
parser. Useful for comparison of types with `=~` such as in `if $some_value | ||
=~ Array[String] {` *Type*: rvalue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you meant this to say:
as in if type_of($some_value) <= Array[String] { ... }
The `type()` function will cease to work on the new parser because 'type' is a reserved keyword. The `type3x()` function may be used to continue similar functionality, but will be deprecated in favor of the built-in typing system. The `type_of()` function has been included to introspect types in the new parser.
+1 on merging this |
(MODULES-1473) Deprecate type() function for new parser
The
type()
function will cease to work on the new parser because 'type' is a reserved keyword. Thetype3x()
function may be used to continue similar functionality, but will be deprecated in favor of the built-in typing system.The
type_of()
function has been included to introspect types in the new parser.