Next / Previous / Contents / TCC Help System / NM Tech homepage

14.2. Strong typing errors

These are errors that would have been caught at compile time in a more strongly typed language such as Java.

  1. Somewhere on a listing I noted that I needed a line of this form:

    import abbr as abbrModule
    

    but it never got added to the imports.

  2. Neglected to import the sys module; catweb needs it to retrieve its command line arguments.

  3. In the addArchive() function, the discussion of prime 1 states that the ArchiveIndex.readFile() method reads the index, but the code was wrong:

        archIndex = ArchiveIndex(catalog, archFileName)
    

    It should be:

        archIndex = ArchiveIndex.readFile(catalog, archFileName)
    

  4. In the addArchImage() function, the module containing the class constructor for BirdId was the wrong one:

            birdId = txny.BirdId.parse(txny, rawBirdId)
    

    It should be:

            birdId = abbrModule.BirdId.parse(txny, rawBirdId)
    

  5. In TaxonPhotoSet._addContained(), this code:

            childTaxon = self.childContaining(newTaxon)
    

    should be:

            childTaxon = self.taxon.childContaining(newTaxon)
    

  6. In TaxonPhotoSet._addContained(), this code added a Taxon object as a value in the self._childMap dictionary, but it should have been a TaxonPhotoSet object. The erroneous code:

            try:
                childNode = self._childMap[childTaxon.txKey]
            except KeyError:
                childNode = TaxonPhotoSet(childTaxon)
                self._childMap[childTaxon.txKey] = childTaxon
    

    Correct code:

            try:
                childNode = self._childMap[childTaxon.txKey]
            except KeyError:
                childNode = TaxonPhotoSet(childTaxon)
                self._childMap[childTaxon.txKey] = childNode
    

  7. Neglected to import the os module; used in FormPhotoSet.pathName() to assemble directory and file names into a path.

  8. In FormPhotoSet.buildPage(), this statement has a typo:

            titleText  = ("Shipman's bird photo index: %s" %
                            seld.birdId.engComma())
    

    It should be:

            titleText  = ("Shipman's bird photo index: %s" %
                            self.birdId.engComma())
    

  9. In FormPhotoSet._addThumbnail(), the call to xc.Element omitted the name of the new element:

            td = xc.Element(tr, valign="top", align="center")
    

    It should be:

            td = xc.Element(tr, "td", valign="top", align="center")
    

  10. In FormPhotoSet._addThumbnail(), the code to extract the catalog number left out a level:

            href = "thumb/%s.jpg" % archImage.catNo
    

    It should be:

            href = "thumb/%s.jpg" % archImage.original.catNo
    

  11. In FormPhotoSet._addSize(), I wasn't paying attention to operator precedence. Here is the erroneous code:

                xc.Text(divPercent, "%.2f%%" %
                          100.0 * thisFramePixels / fullFramePixels)
    

    I should have parenthesized the expression on the second line. As it was, it was grouped as “("%.2f%%" % 100.0) * ...”. Better code, moving the percentage calculation to a separate line:

                framePercent = 100.0 * thisFramePixels / fullFramePixels
                xc.Text(divPercent, "%.2f%%" % framePercent)
    

  12. In FormPhotoSet._addData(), this line omitted its first argument:

            if  archImage.original.loc:
                xc.Text(": %s" % archImage.original.loc)
    

    It should be:

            if  archImage.original.loc:
                xc.Text(majorDiv, ": %s" % archImage.original.loc)
    

  13. In FormPhotoSet._addData(), this line:

            # [ td  :=  td with a new div element added containing
            #           arch.original.note ]
            if  arch.original.note:
                noteDiv = xc.Element(td, "div")
                xc.Text(noteDiv, arch.original.note)
    

    should be:

            # [ td  :=  td with a new div element added containing
            #           archImage.original.note ]
            if  archImage.original.note:
                noteDiv = xc.Element(td, "div")
                xc.Text(noteDiv, archImage.original.note)
    

  14. In TaxonPhotoSet._buildMultiForms(), the call to ._buildFormLine() omitted the first argument.

              self._buildFormLine(self._formMap[formName])
    

    It should be:

              self._buildFormLine(parent, self._formMap[formName])