Next / Previous / Contents / Shipman's homepage

14.3. LocGroup.inherit(): Implement inheritance for locations

This method is used to find the effective locality data when one element inherits locality from a parent element. For design notes on the inheritance process, see Section 13.2, “Sighting.getLocGroup(): Find a sighting's effective locality”.

birdnotes.py
# - - -   L o c G r o u p . i n h e r i t

    def inherit(self, parentGroup):
        """Implement locality inheritance.
        """

Here, we make heavy use of Python's “A or B” operator to set a value to A if A is not None, or to B if A is None.

birdnotes.py
        #-- 1 --
        # [ if self.loc is None ->
        #     loc  :=  parentGroup.loc
        #   else ->
        #     loc  :=  self.loc ]
        loc = self.loc or parentGroup.loc

        #-- 2 --
        # [ simile ]
        gps = self.gps or parentGroup.gps
        locDetail = self.locDetail or parentGroup.locDetail

See Section 14.1, “LocGroup.__init__().

birdnotes.py
        #-- 3 --
        return LocGroup(loc, gps, locDetail)