Kristian Nybo

Results 11 comments of Kristian Nybo

@hynek Related to this, would it make sense for the following to produce an error? ``` @attr.s(auto_attribs=True) class MyClass(object): class_var = 5 instance_var: str = 'foo' ``` Currently (in attrs...

@samuelcolvin Great, thanks for the quick reply! I somehow overlooked (I blame sleep deprivation) that validators can be used for parsing as well as validating. In a sense that feels...

```py class TypedArray(numpy.ndarray): @classmethod def __get_validators__(cls): yield cls.validate_type @classmethod def validate_type(cls, val): return numpy.array(val, dtype=cls.inner_type) class ArrayMeta(type): def __getitem__(self, t): return type('Array', (TypedArray,), {'inner_type': t}) class Array(numpy.ndarray, metaclass=ArrayMeta): pass class...

Right, I was looking for something like `__serialise__`. Would it be difficult to add? (I imagine it might not be, but I'm not that familiar with pydantic's internals.)

@samuelcolvin So would it be as simple as returning ```py { get_key(k): if hasattr(v, '__serialise__') then v.__serialise__() else v for k, v in self._iter( # ... ) } ``` from...

Hmm, I thought the recursion was already taken care of by `._get_value` and `._iter`? That is, `.dict()` calls `._iter`, which calls `._get_value` for each field; `._get_value` sees that the `foobar`...

@samuelcolvin Hmm, one thing that just occurred to me is that if `__serialise__` is a method of `Array`, then I guess that means that one needs to make sure that...

I was thinking specifically of a scenario like ```py class Foo: arr: Array foo = Foo(arr=numpy.array([1,2,3])) # ... foo.arr = returns_numpy_arrays() ``` so the `Array` constructor wouldn't get called. I...

Ah, good point, so I can just add that to the `Config` class of `MyBaseModel` to make that the default behavior in all classes (intended to be serialized).

@dmontagu I can't comment on performance, but if this is implemented using `json_encoders`, doesn't that mean that you still couldn't customize what happens when you call `.dict()`? This doesn't matter...