[reportlab-users] Puzzling Error

Jerome Alet reportlab-users@reportlab.com
Wed, 6 Nov 2002 12:06:55 +0100

On Wed, Nov 06, 2002 at 10:09:47AM +0000, Robin Becker wrote:

> .... I think it's fine that we have pycanvas for all versions. I just
> don't like it when I can't figure out what the real problem is. I
> thought it was the way in which the __str__ etc methods get called, but
> can't be sure.

OK, got it, at least partially I suppose.

I've finally tested some simple code on 1.5.2, 2.1.3 and 2.2.x, I've
found a 1.5.2 on another machine.

here it is: 

whenever an attribute access is done in pycanvas's classes instances,
the attribute is faked by creating a new instance of one of
pycanvas classes.

however two subsequent accesses to the same attribute produce two 
different instances to represent the very same value, and so the 
hash value created to access to the font dictionnary in 
pdfmetrics.py is different each time, so the font is never found. 

the str() call solved this.

it seems that 2.2 is intelligent enough to either return the previous
instance, or more probably put the new one at the same physical location
than the old one (who was probably automatically deleted when unused).

anyone could confirm ?

the best solution would be for pycanvas to cache attribute access, 
but I don't know if this is feasible especially wrt direct attribute 
modification which may not pass through pycanvas's wrappers. 

the easier solution is probably the small str() hacks in pdfmetrics,
but I wonder if such a problem wouldn't reappear elsewhere, probably
in user code which would use pycanvas and canvas attributes as
mapping keys.

Jerome Alet