It looks like just overriding `_hash_` should do the trick. It's a "cpdef" 
method so the code should be there to check if it's overridden on a 
descendant class instance. There will be a performance degradation, 
although it will be mild because the hash is cached. If that's a problem, 
you can cythonize ParkingFunction and override the whole equality and 
"__hash__" infrastructure on the class. If that's too much work it's an 
indication that perhaps it's not such a big problem :-)

The workaround is to just not use the specialized "ParkingFunctions of 
fixed length" parents, so that all the parking functions you use have the 
same (generic) parent. Or only use specific parents, depending on what is 
more suitable for your code. More generally "sets with elements from mixed 
parents" are not really supported or at least buggy; because of the 
fundamental problem with transitivity of equality (and the interactions 
with hash).

While for parking functions this may be relatively solvable, you should 
consider the problem you're running into a code smell. Defensive coding 
practices in sagemath would avoid these constructions in the first place. 
It's not really ideal to have undocumented or unenforced recommended 
practices, but in this case it's a consequence of the requirement in 
sagemath to stretch equality notation to something that globally is no 
longer transitive, together with sets that don't know about parents or 
coercion. A mitigating workaround would be a set that is aware of the 
parent of its elements. Then testing membership can coerce the candidate 
into the appropriate parent (if that fails, it can't possibly be in the 
set) and then hashes only need to be consistent with equality within the 
parent. If that's not the case, you tend to really have a bug, rather than 
just an inconvenient instance of inconsistencies that are bound to exist.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/d6814a9a-6581-4ef5-baa9-c2efe5afeb10n%40googlegroups.com.

Reply via email to