Jira (PUP-8492) Move the empty() function from stdlib to puppet

2 views
Skip to first unread message

Henrik Lindberg (JIRA)

unread,
Feb 26, 2018, 4:21:03 PM2/26/18
to puppe...@googlegroups.com
Henrik Lindberg moved an issue
 
Puppet / Improvement PUP-8492
Move the empty() function from stdlib to puppet
Change By: Henrik Lindberg
Fix Version/s: PUP 5.5.0
Fix Version/s: PUP 5.5.0
Key: BOLT PUP - 353 8492
Project: Puppet Task Runner
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.5.1#75006-sha1:7df2574)
Atlassian logo

Henrik Lindberg (JIRA)

unread,
Feb 27, 2018, 1:37:03 PM2/27/18
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Release Notes Summary: The {{empty()}} function has moved from stdlib to puppet , and now also supports answering if a {{Binary}} value is empty (has zero bytes) .

Henrik Lindberg (JIRA)

unread,
Feb 27, 2018, 2:26:03 PM2/27/18
to puppe...@googlegroups.com

Thomas Hallgren (JIRA)

unread,
Mar 2, 2018, 4:15:02 AM3/2/18
to puppe...@googlegroups.com
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Thomas Hallgren (JIRA)

unread,
Mar 2, 2018, 4:15:02 AM3/2/18
to puppe...@googlegroups.com
Thomas Hallgren assigned an issue to Unassigned
 
Change By: Thomas Hallgren
Assignee: Thomas Hallgren

Henrik Lindberg (JIRA)

unread,
Mar 2, 2018, 9:19:02 AM3/2/18
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Sprint: Platform Core KANBAN

Henrik Lindberg (JIRA)

unread,
Mar 8, 2018, 6:41:02 AM3/8/18
to puppe...@googlegroups.com
Henrik Lindberg commented on Improvement PUP-8492
 
Re: Move the empty() function from stdlib to puppet

A follow up fix was merged to master at b468cd4 fixing the issue that empty() must return true for undef.
That also adds deprecation warnings for the undef case.

Kenn Hussey (JIRA)

unread,
Mar 9, 2018, 2:19:10 PM3/9/18
to puppe...@googlegroups.com
Kenn Hussey commented on Improvement PUP-8492

Henrik Lindberg please add release notes for this issue, if needed. Thanks! 

Henrik Lindberg (JIRA)

unread,
Mar 9, 2018, 9:14:03 PM3/9/18
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Release Notes Summary: The {{empty()}} function has moved from stdlib to puppet, and now also supports answering if a {{Binary}} value is empty (has zero bytes). Calling empty with an undef value, or with a numeric value is now also deprecated and will issue a warning.

Kenn Hussey (JIRA)

unread,
Mar 19, 2018, 3:22:03 PM3/19/18
to puppe...@googlegroups.com
Kenn Hussey commented on Improvement PUP-8492

Henrik Lindberg please add release notes for this issue if needed, thanks!

Henrik Lindberg (JIRA)

unread,
Mar 19, 2018, 3:46:03 PM3/19/18
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Release Notes: New Feature

Henrik Lindberg (JIRA)

unread,
Mar 19, 2018, 3:47:06 PM3/19/18
to puppe...@googlegroups.com
Henrik Lindberg commented on Improvement PUP-8492
 
Re: Move the empty() function from stdlib to puppet

Kenn Hussey It already had a release note - just that it was not flipped from "None"

Eric Sorenson (JIRA)

unread,
Mar 29, 2018, 1:37:02 PM3/29/18
to puppe...@googlegroups.com
Eric Sorenson commented on Improvement PUP-8492

Henrik Lindberg Why deprecate the behaviour that empty on an undef variable is true? Is it going to change in the future? What is the workaround for people who currently use empty() to determine whether a variable is undef?

Henrik Lindberg (JIRA)

unread,
Apr 3, 2018, 3:53:04 AM4/3/18
to puppe...@googlegroups.com

Earlier, since the function was a 3.x function it was important to handle undef the same way as an empty string because empty strings were considered to be equivalent to undef - it was just a mess. Now with data types and automatic type checking there should be a lot less confusion over what something is - and treating undef as "an empty container" is far more likely to mask a bug than being useful.

So, what to use instead of using empty() or !empty() to check if something is/not-is undef depends on why that check is made. Also, if the check is made to raise an error, the entire construct can be replaced by using either automatic type checking, or calling assert_type

Examples for checking if something is:

  • undef: $x =~ Undef, or $x == undef
  • not undef: $x =~ NotUndef, $x !~ Undef, or $x != undef
  • undef or an empty string: $x =~ Optional[String[0,0]]
  • non-empty string: $x =~ String[1]
  • non-empty array: $x =~ Array[1]
  • non-empty hash: $x =~ Hash[1]
  • non-empty array or hash: $x =~ Collection[1]
  • the same as stdlib 3.x version of empty: $x =~ Variant[String[0,0], Collection[0,0], Undef]

If using empty() to mean "unspecified" and having it in multiple places in a module, it could be of value to define a data type - say MyModule::Unspecified like this:

type MyModule::Unspecified = Variant\[String\[0,0], Collection\[0,0], Undef]

and then replace empty($x) with $x =~ MyModule::Unspecified

Or, if so preferred, define a function like this:

function mymodule::unspecified(Any $x) {
  $x =~ Variant\[String\[0,0], Collection\[0,0], Undef]
}

and use it instead of empty().

Eric Sorenson (JIRA)

unread,
Apr 3, 2018, 1:43:04 PM4/3/18
to puppe...@googlegroups.com
Eric Sorenson commented on Improvement PUP-8492

Sure, people could opt in to that if they were having problems. But (a) that syntax is all much more advanced than the if empty($foo) pattern, and (b) we can't find and fix all the instances of this, which are used in everything from other stdlib functions to the PE internal modules, so I don't think it's appropriate to mark it for a deprecation/removal.

Henrik Lindberg (JIRA)

unread,
Apr 4, 2018, 9:31:04 AM4/4/18
to puppe...@googlegroups.com

ok, will add a ticket and remove the deprecation

Henrik Lindberg (JIRA)

unread,
Apr 4, 2018, 10:16:04 AM4/4/18
to puppe...@googlegroups.com

PUP-8623 for the removal of the deprecation of undef

John Duarte (JIRA)

unread,
Oct 21, 2019, 10:55:04 AM10/21/19
to puppe...@googlegroups.com
John Duarte updated an issue
 
Change By: John Duarte
QA Risk Assessment: Needs Assessment No Action
Reply all
Reply to author
Forward
0 new messages