Skip to content

Commit

Permalink
Fix slots for view
Browse files Browse the repository at this point in the history
  • Loading branch information
levsh committed Oct 18, 2024
1 parent 4095382 commit 32b1d37
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cwtch/cwtch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,8 +1119,9 @@ def update_type(tp, view_names: Sequence[str]):
if "__slots__" in __dict__:
__slots__ += tuple(x for x in __dict__["__slots__"] if x not in __slots__)
__dict__["__slots__"] = __slots__
for f_name, f in __cwtch_fields__.items():
__dict__[f_name] = f
else:
for f_name, f in __cwtch_fields__.items():
__dict__[f_name] = f
__dict__.pop("__dict__", None)
view_cls = type(view_cls.__name__, view_cls.__bases__, __dict__)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_cwtch.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,15 @@ class BV2(B, A.V2):
assert not issubclass(B.V1, A.V1)
assert issubclass(B.V2, A.V2)

def test_slots(self):
@dataclass(slots=True)
class M:
i: int

@view
class V1(M):
pass


class TestJsonSchema:
def test_make_json_schema(self):
Expand Down

0 comments on commit 32b1d37

Please sign in to comment.