Skip to content

(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

Merged
merged 1 commit into from
Jan 8, 2015

Conversation

hunner
Copy link
Contributor

@hunner hunner commented Dec 16, 2014

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.

@hlindberg
Copy link
Contributor

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.
Copy link
Contributor

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').

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True.

@hunner
Copy link
Contributor Author

hunner commented Jan 6, 2015

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 ?

@hunner
Copy link
Contributor Author

hunner commented Jan 7, 2015

Tests pushed.

Someone labeled this "backwards incompatible" though it is backwards compat.

#! /usr/bin/env ruby -S rspec

require 'spec_helper'
require 'puppet/pops'
Copy link
Contributor

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") }
#
Copy link
Contributor

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") }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@hunner hunner force-pushed the fix_type branch 2 times, most recently from a34db4e to a275635 Compare January 8, 2015 00:07
@@ -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
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@hlindberg
Copy link
Contributor

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
Copy link
Contributor

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.
@hlindberg
Copy link
Contributor

+1 on merging this

cyberious added a commit that referenced this pull request Jan 8, 2015
(MODULES-1473) Deprecate type() function for new parser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants