[issue33395] TypeError: unhashable type: 'instancemethod'

2018-05-01 Thread R. David Murray

R. David Murray  added the comment:

Functions/methods should be immutable, so yes, I think it is a safe assumption 
that they should be hashable, and a bug if they are not.  I seem to vaguely 
recall that there is some other part of the cpython machinery that depend on 
being able to test function/method equality and assumes that they are 
immutable, which implies they should be hashable.

I'll close this; Christian can reopen it if he thinks there is an actual bug 
lurking here.

--
resolution:  -> third party
stage:  -> resolved
status: open -> closed
type: crash -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33395] TypeError: unhashable type: 'instancemethod'

2018-05-01 Thread Siming Yuan

Siming Yuan  added the comment:

i just discovered cython v0.28 no longer creates instancemethod, so this bug 
should technically no longer show up after upgrading cython.
(related cython bug https://github.com/cython/cython/pull/2105)

so the question remains - is it a good idea to assume all type(obj).__repr__ is 
hashable?

if so, we can close this bug.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33395] TypeError: unhashable type: 'instancemethod'

2018-05-01 Thread R. David Murray

R. David Murray  added the comment:

Ah, in the absence of a traceback I think I misunderstood the problem (I failed 
to actually look at the code :)

Given what you say about the slotwrapper, I'm not sure, but I'm guessing that 
that means cython isn't using the PyInstanceMethod_Type as intended.  That 
doesn't mean it can't be fixed (though if true it makes it less likely that 
we'll fix it, unfortunately), but you'll have to figure out what the difference 
is between how it is used by cython and cpython.  I've nosied Christian, maybe 
he'll remember why the hash is commented out.

--
nosy: +christian.heimes

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33395] TypeError: unhashable type: 'instancemethod'

2018-04-30 Thread Siming Yuan

Siming Yuan  added the comment:

having a tough time trying to reproduce this issue in pure python.

any clue as to how to create a __repr__ that's unhashable?

class UnhashableRepr(dict):
__repr__ = _testcapi.instancemethod(dict.__repr__)

doesn't work because that turns into a  which becomes hashable.

i'd love to provide a patch, seems trivial to fix, but wouldn't want to do so 
without some tests.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33395] TypeError: unhashable type: 'instancemethod'

2018-04-30 Thread R. David Murray

R. David Murray  added the comment:

The non-hashable case should be handled by a default function, I would think.  
It should be fairly straightforward to come up with a reproducer that does not 
involve cython, which I think would be the first step.

--
nosy: +r.david.murray

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33395] TypeError: unhashable type: 'instancemethod'

2018-04-30 Thread Siming Yuan

New submission from Siming Yuan :

in Python 3.5 it the pprint.PrettyPrinter mechanism got an overhaul, relying on 
PrettyPrinter._dispatch dict-lookup based on obj.__repr__ type.

This breaks any Cythonized 3rd party libraries that used to be pretty-printable 
in Python3.4.

type(object).__repr__


since instancemethod_hash function has been commented out:
https://github.com/python/cpython/blob/c30098c8c6014f3340a369a31df9c74bdbacc269/Objects/classobject.c#L569


oddly the behavior is different between Linux and Mac.

The same object in Linux returns cyfunction, and is hashable,
where as under the same CPython version in Mac, it returns instancemethod, 
rendering it unhashable.
(based on Cython 0.27.3)

note that this isn't exactly something related directly to the implementation 
of Cython.

the old logic in Python <3.4 pprint was not pretty (pun not intended), but 
relied solely on type checking,
where as the new implementation depends on hashing, which introduces this bug.

--
messages: 315964
nosy: siming85
priority: normal
severity: normal
status: open
title: TypeError: unhashable type: 'instancemethod'
type: crash
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com