This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Mikołaj Babiak, ncoghlan, rhettinger
Date 2017-09-25.04:46:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1506314786.64.0.257444151571.issue31145@psf.upfronthosting.co.za>
In-reply-to
Content
My rationale for asking "What if we just changed heapq back to working closer to the way it used to work?" is that it's a case where arbitrarily ordering unorderable tuples made sense, and reverting it to the old behaviour is reasonably safe:

- some Py3 heapq code that previously raised TypeError would start using an arbitrary ordering instead
- Py2 heapq code would get a *different* arbitrary ordering in Py3, but it would still get an arbitrary ordering

I don't feel especially strongly about that though, so if you prefer the approach of defining a new more explicit idiom to replace the old "make a tuple" one, I think a new wrapper type is a reasonable way to go, but using "Prioritize" as a name is probably too specific to the PriorityQueue use case.

As a more generic name, "KeyedItem" might work:

```
@functools.total_ordering
class KeyedItem:

    def __init__(self, key, item):
        self.key = key
        self.item = item

    def __eq__(self, other):
        return self.key == other.key

    def __lt__(self, other):
        return self.key < other.key
```

So applying an arbitrary key function would look like:

    decorated = [KeyedItem(key(v), v) for v in values]

And if it was a tuple subclass, it would also work with APIs like the dict constructor.
History
Date User Action Args
2017-09-25 04:46:26ncoghlansetrecipients: + ncoghlan, rhettinger, Mikołaj Babiak
2017-09-25 04:46:26ncoghlansetmessageid: <1506314786.64.0.257444151571.issue31145@psf.upfronthosting.co.za>
2017-09-25 04:46:26ncoghlanlinkissue31145 messages
2017-09-25 04:46:26ncoghlancreate