Declared List Throws NoneType Exception

I have a snippet from another python module that throws an exception ( AttributeError: 'NoneType' object has no attribute 'append'). Excerpt:

def generateFragments(self):
    tr = self.deviceTransform()
    if tr is None:
        return
    pts = np.empty((2,len(self.data['x'])))
    pts[0] = self.data['x']
    pts[1] = self.data['y']
    pts = fn.transformCoordinates(tr, pts)
    self.fragments = []
    pts = np.clip(pts, -2**30, 2**30) ## prevent Qt segmentation fault.
                                      ## Still won't be able to render correctly, though.
    for i in xrange(len(self.data)):
        rec = self.data[i]
        pos = QtCore.QPointF(pts[0,i], pts[1,i])
        x,y,w,h = rec['fragCoords']
        rect = QtCore.QRectF(y, x, h, w)
        self.fragments.append(QtGui.QPainter.PixmapFragment.create(pos, rect))

And the error message:

[14:35:59]  Ignored exception:

    |==============================>>
    |  Traceback (most recent call last):
    |    File "/usr/lib/pymodules/python2.7/pyqtgraph/debug.py", line 35, in w
    |      func(*args, **kwds)
    |    File "/usr/lib/pymodules/python2.7/pyqtgraph/graphicsItems/ScatterPlotItem.py", line 714, in paint
    |      self.generateFragments()
    |    File "/usr/lib/pymodules/python2.7/pyqtgraph/graphicsItems/ScatterPlotItem.py", line 685, in generateFragments
    |      self.fragments.append(QtGui.QPainter.PixmapFragment.create(pos, rect))
    |  AttributeError: 'NoneType' object has no attribute 'append'
    |  
    |==============================<<

This is not a “fix my mistake” question, but a “how is this possible” question. A couple of lines above are self.fragmentsdeclared as an empty list. From now on, the only modification self.fragmentsis the challenge append(). How can I change the type? Is there a possible error in the add operation that can change the list type to NoneType?

+4
source share
1 answer

Two possibilities come to me:

  • concurrency (as per @ekhumoro's comment).
  • __getattribute__, .
0

All Articles