cy99 / shedskin

Automatically exported from code.google.com/p/shedskin
0 stars 0 forks source link

hashing itertools.imap? #56

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Code:
from itertools import imap

def dumps(board):
    return hash(imap(tuple, board))

if __name__ == "__main__":
    dumps([[item for item in range(4)] for row in range(4)])

Error attached. shedskin generates c++ code, but g++ can't compile.

Original issue reported on code.google.com by frap...@gmail.com on 22 Jan 2010 at 6:55

Attachments:

GoogleCodeExporter commented 9 years ago
thanks! I will have a look this weekend.

Original comment by mark.duf...@gmail.com on 22 Jan 2010 at 7:44

GoogleCodeExporter commented 9 years ago
are you sure you didn't mean to use this:

hash(tuple(imap(tuple, board)))

because hashing an iterator seems a bit strange to me.. I will have to lookup 
what
happens then in CPython.. :-) using the above it works with shed skin (SVN at 
least).

Original comment by mark.duf...@gmail.com on 22 Jan 2010 at 7:54

GoogleCodeExporter commented 9 years ago

Original comment by mark.duf...@gmail.com on 22 Jan 2010 at 7:55

GoogleCodeExporter commented 9 years ago
Yes, it sounds a bit strange :) It's a little bug. I don't know if hash 
evaluates all
the expression or if it starts hashing iterating it (but this kind of writing 
will be
meaningless if it uses the first behaviour... but generators are expressed like
tuples -> (...) :) ).

Original comment by frap...@gmail.com on 22 Jan 2010 at 8:17

GoogleCodeExporter commented 9 years ago
Also, another problem (for me) if I use return hash(tuple(imap(tuple, board))).

Original comment by frap...@gmail.com on 22 Jan 2010 at 10:28

Attachments:

GoogleCodeExporter commented 9 years ago
ah, sorry, I seem to have broken extension module support yesterday. it should 
be
fixed now ^^

Original comment by mark.duf...@gmail.com on 23 Jan 2010 at 8:17

GoogleCodeExporter commented 9 years ago
hm, hashing it just takes the memory address:

>>> a = imap(tuple, [[1,2,3]])
>>> id(a) == hash(a)
True

I will have to fix shedskin in any case to do that here.

Original comment by mark.duf...@gmail.com on 23 Jan 2010 at 8:29

GoogleCodeExporter commented 9 years ago
on revisiting issues, I don't think supporting hashing of functions would be 
useful
in shedskin.. it also occurs here only because of buggy code. so I'm closing 
this issue.

Original comment by mark.duf...@gmail.com on 21 Mar 2010 at 9:51