Skip to content

Commit

Permalink
Merge 46f3305 into 2ad07ff
Browse files Browse the repository at this point in the history
  • Loading branch information
cdonovick committed Jul 10, 2019
2 parents 2ad07ff + 46f3305 commit ebbf2e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion hwtypes/adt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .adt_meta import TupleMeta, ProductMeta, SumMeta, EnumMeta, is_adt_type
from collections import OrderedDict
from types import MappingProxyType

__all__ = ['Tuple', 'Product', 'Sum', 'Enum']
Expand Down Expand Up @@ -80,7 +81,7 @@ def __repr__(self):

@property
def value_dict(self):
d = {}
d = OrderedDict()
for k in type(self).field_dict:
d[k] = getattr(self, k)
return MappingProxyType(d)
Expand Down
3 changes: 2 additions & 1 deletion hwtypes/adt_meta.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import itertools as it
import typing as tp
from abc import ABCMeta, abstractmethod
from collections import OrderedDict

import weakref

Expand Down Expand Up @@ -190,7 +191,7 @@ def from_fields(mcs, fields, name, bases, ns, **kwargs):
if '_field_table_' in ns:
raise ReservedNameError('class attribute _field_table_ is reserved by the type machinery')
else:
ns['_field_table_'] = dict()
ns['_field_table_'] = OrderedDict()

def _get_tuple_base(bases):
for base in bases:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_adt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ class Pr(Product):
x = En1
y = En2

class Pr2(Product):
x = En1
y = En2

class Pr3(Product):
y = En2
x = En1

Su = Sum[En1, Pr]

Tu = Tuple[En1, En2]
Expand Down Expand Up @@ -106,6 +114,10 @@ def test_product():
with pytest.raises(TypeError):
p[0] = En2.c

assert Pr != Pr2
assert Pr.field_dict == Pr2.field_dict
assert Pr.field_dict != Pr3.field_dict


def test_sum():
assert set(Su.enumerate()) == {
Expand Down

0 comments on commit ebbf2e3

Please sign in to comment.