j...@math.brown.edu writes:

 > Instead of the proposals like "hash.from_iterable()", would it make sense
 > to allow tuple.__hash__() to accept any iterable, when called as a
 > classmethod?
[...]

 > Would this API more cleanly communicate the algorithm being used and the
 > implementation, while making a smaller increase in API surface area
 > compared to introducing a new function?

I don't understand what you're proposing.  There are three problems
with the API.  First, the "obvious" meaning of
"tuple.__hash__(iterable)" is "hash(tuple(iterable))", and that's the
obvious spelling.  Second, there's no reason for a dunder method to be
polymorphic; this is hardly discoverable.  Third, dunders are normally
not called from user code (including class implementations, although
they're less ugly there), suggesting that there should be a helper for
this.

I'm unclear on how the function is supposed to be implemented, since
presumably tuple.__hash__ knows about the tuple data structure's
implementation (memory layout), but it can't know about an arbitrary
iterable.

Steve


_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to