Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-10270

Allow testing for data types with defined()

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Accepted
    • Priority: Normal
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Functions
    • Labels:
      None
    • Template:
    • Sub-team:
    • Team:
      Froyo
    • QA Risk Assessment:
      Needs Assessment

      Description

      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

       

        Attachments

          Activity

            People

            Assignee:
            henrik.lindberg Henrik Lindberg
            Reporter:
            baurmatt Matthias Baur
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:

                Zendesk Support