Best Practices for Internal Package Structure

2016-04-04 Thread Josh B.
My package, available at https://github.com/jab/bidict, is currently laid out like this: bidict/ ├── __init__.py ├── _bidict.py ├── _common.py ├── _frozen.py ├── _loose.py ├── _named.py ├── _ordered.py ├── compat.py ├── util.py I'd like to get some more feedback on a question about this layout

__hash__ and ordered vs. unordered collections

2017-11-20 Thread Josh B.
Suppose we're implementing an immutable collection type that comes in unordered and ordered flavors. Let's call them MyColl and MyOrderedColl. We implement __eq__ such that MyColl(some_elements) == MyOrderedColl(other_elements) iff set(some_elements) == set(other_elements). But

Re: __hash__ and ordered vs. unordered collections

2017-11-20 Thread Josh B.
On Monday, November 20, 2017 at 1:55:26 PM UTC-5, Chris Angelico wrote: > But what you have is the strangeness of non-transitive equality, which > is likely to cause problems. But this is exactly how Python's built-in dict and OrderedDict behave: >>> od = OrderedDict([(1, 0), (2, 0), (3, 0)])

Re: __hash__ and ordered vs. unordered collections

2017-11-20 Thread Josh B.
On Monday, November 20, 2017 at 2:31:40 PM UTC-5, MRAB wrote: > What if there are duplicate elements? > > Should that be MyColl(some_elements) == MyOrderedColl(other_elements) > iff len(some_elements) == len(other_elements) and set(some_elements) == > set(other_elements)? Yes, that's what I

Re: __hash__ and ordered vs. unordered collections

2017-11-21 Thread Josh B.
On Monday, November 20, 2017 at 3:17:49 PM UTC-5, Chris Angelico wrote: > Neither is perfect. You have to take your pick between them. Right on, thanks for weighing in, Chris. Your responses have been very helpful. I wouldn't feel comfortable claiming the authority to make this call alone. But