thriftrw / thriftrw-python

A Thrift encoding library for Python
MIT License
36 stars 10 forks source link

struct constructor doesn't check nested types #33

Closed blampe closed 9 years ago

blampe commented 9 years ago

I don't think we're recursing into lists/maps to reconstruct the native type:

 def test_constructor_behavior_with_nested_types(loads):
     Struct = loads('''struct Struct {
         1: optional list<string> strings;
     }''').Struct

     with pytest.raises(TypeError) as exc_info:
         Struct(strings=[1])
E   Failed: DID NOT RAISE
abhinav commented 9 years ago

This will be checked during serialization/deserialization.

blampe commented 9 years ago

This makes interacting with the object awkward, though, especially when re-hydrating it from JSON.

abhinav commented 9 years ago

Fair. Although we can't drop validation during serialization because that will just fail with cryptic messages when struct.pack fails. If we're okay with the added cost, I see no problem with doing it in the constructor too.

abhinav commented 9 years ago

Fixed by 0.4.0