[albatross-users] Bug with persistentlists and such (1.10)

Tollef Fog Heen tfheen at raw.no
Wed Nov 12 04:03:54 EST 2003


* "Michael C. Neel" 

| Doesn't map imply a function call for every element of the list?

If it is has a list interface, then yes.  But if it has a list
interface, we want to do that anyhow.  Look at what the code does:

        try:
            if str(value_attr) in map(str, value):
                ctx.write_content(' checked')
        [handle exception]

Compare this with the original code:

        if type(value) in (type([]), type(())):
            if str(value_attr) in map(str, value):
                ctx.write_content(' checked')

As you can see, it still does the same thing, and map will fail on
objects which doesn't have a list interface.  If they _do_ have a list
interface, it's desirable that expr does work as expected.  If it
looks like a list, walks like a list and talks like a list, then it is
a list.

| A bit high on the overhead don't you think for a type check?

Doing an interface check instead of type check?  And doing it in C
instead of Python (map is C)?  No, that's lower overhead, not higher.

| I'm not sure how it checks now, but a test of "isinstance(val,
| list)" will catch lists and classes built from list.

What do you mean by «classes built from list»?  List is a native type,
it's not a class, so you can't inherit from it.

-- 
Tollef Fog Heen                                                        ,''`.
UNIX is user friendly, it's just picky about who its friends are      : :' :
                                                                      `. `' 
                                                                        `-  



More information about the Albatross-users mailing list