#29 Have xmd default as an empty dictionary and not allow None
Merged 7 years ago by ralph. Opened 7 years ago by mprahl.
Unknown source xmd-dict-type-only  into  master

file modified
+2 -2
@@ -75,7 +75,7 @@

          self.community = ""

          self.documentation = ""

          self.tracker = ""

-         self.xmd = None

+         self.xmd = dict()

          self.profiles = dict()

          self.api = ModuleAPI()

          self.filter = ModuleFilter()
@@ -630,7 +630,7 @@

  

      @xmd.setter

      def xmd(self, d):

-         if d is not None and not isinstance(d, dict):

+         if not isinstance(d, dict):

              raise TypeError("xmd: data type not supported")

          self._xmd = d

  

file modified
+1 -1
@@ -51,7 +51,7 @@

          self.assertSetEqual(self.mmd.module_licenses, set(["MIT"]))

          self.assertSetEqual(self.mmd.content_licenses,

                  set(["Beerware", "GPLv2+", "zlib"]))

-         self.assertIsNone(self.mmd.xmd)

+         self.assertEqual(self.mmd.xmd, {'some_key': 'some_data'})

          self.assertDictEqual(self.mmd.buildrequires,

                  {

                      "generational-core" : "and-its-stream-name",

file modified
+4 -3
@@ -38,9 +38,10 @@

              - GPLv2+

              - zlib

      # Extensible metadata block

-     # A dictionary of user-defined keys and values.  May be null.

-     # Optional.  Defaults to null.

-     xmd: ~

+     # A dictionary of user-defined keys and values.

+     # Optional.  Defaults to an empty dictionary.

+     xmd:

+       some_key: some_data

      # Module dependencies, if any.  Optional.

      # TODO: Provides, conflicts, obsoletes, recommends, etc.

      # TODO: Stream name globbing or regular expression support

Before this PR, xmd would default to None which made coding against it messy such as having to check the type before checking if a key is set. This now defaults to a dictionary so that you can simply do the following to check if xmd has a key set:

x = mmd.xmd.get('some_key')

Pull-Request has been merged by ralph

7 years ago