Jira (PUP-10270) Allow testing of data types with defined()

2 views
Skip to first unread message

Matthias Baur (JIRA)

unread,
Feb 6, 2020, 5:59:05 AM2/6/20
to puppe...@googlegroups.com
Matthias Baur created an issue
 
Puppet / Improvement PUP-10270
Allow testing of data types with defined()
Issue Type: Improvement Improvement
Assignee: Henrik Lindberg
Components: Functions
Created: 2020/02/06 2:58 AM
Priority: Normal Normal
Reporter: Matthias Baur

It would be nice if I could test if a data type exists. Henrik Lindberg suggested on Slack that this functionality might be easily implemented in the defined() function.

The use case is: As a module maintainer I need to support Puppet 5 and 6. If I want to implemented Deferred I need to do the following to ensure Puppet 5 doesn't try to compile the Deferred data type. This would lead to a compile error.

 

  # $serverversion is empty on 'puppet apply' runs. Just use clientversion.
  $_serverversion    = get('serverversion') ? {
    undef   => $clientversion,
    default => $serverversion,
  }
 
  if versioncmp($clientversion, '6.0') >= 0 and versioncmp($_serverversion, '6.0') >= 0 {
    assert_type(Optional[Variant[String, Deferred]], $content)
  } else {
    assert_type(Optional[String], $content)
  }

It would be nice if I could do something like  this:

if defined('Deferred') {
  assert_type(Optional[Variant[String, Deferred]], $content)
} else {
  assert_type(Optional[String], $content)
}

It would be especially awesome if you could backport this to Puppet 5

 

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages