Released #TypedSettings 24.5.0 today.
It improves testability of Click CLIs by allowing to lazily load default settings (this is not an issues with argparse CLIs).
It also adds support for the lastest and gratest #cattrs version (thx to @tintvrtkovic <3)
https://typed-settings.readthedocs.io/en/latest/changelog.html#v24-5-0
New #cattrs is out (24.1.0) but I'm too exhausted to do a large thread about it. The changelog is pretty large: https://catt.rs/en/stable/history.html#id1
A couple of my favorite features:
Hook factories can have the converter injected as an argument now. This very simple change makes them much more self contained and more fun to write.
Some converter APIs can be used as decorators now, and will read type hints from the decorated functions. It's a small thing but it adds finesse.
@hynek helped focus the docs!
Here's a #Python thing that's been a problem for #cattrs for a long time.
Fundamentally, this is how cattrs works: you give it some data and a type, and it gives you back an instance of that type. That's all well and good until that type is something more complex than a straight-up class. For example, if that type is something like:
- a union (`int | str`)
- a literal
- a protocol
- an ABC (`Sequence`)
- other fancy typing things
it will still work, but it won't type-check.
The moment I know you've all been waiting for with baited breath has arrived; #cattrs 23.2.0 is now out!
See the release notes here: https://github.com/python-attrs/cattrs/releases/tag/v23.2.0
Here's hoping I don't break your stuff, but even if I do you'll learn the value of pinning dependencies so it'll still be to your benefit! That's just how I roll.
A person on the #cattrs issue tracker asked for cattrs to be able to handle unions by iterating through the union members one by one and trying to handle it until one case succeeds.
I think I've seen this approach in other libraries so I tried giving a thoughtful rationale of why I'm not a fan of it: https://github.com/python-attrs/cattrs/issues/423#issuecomment-1699875059
This means cattrs shouldn't be doing this by default. I'm still open to having this on an opt-in basis though, if someone was to contribute it.
First post here 🚨
Recently I published my first blog post on how we used attrs and cattrs to model our API payloads.
Check it out here:
https://medium.com/klaviyo-engineering/powering-our-apis-using-attr-active-dtos-f88f2177d855
With this MR (https://gitlab.com/sscherfke/typed-settings/-/merge_requests/22), #TypedSettings will get its own, built-in converter making #cattrs optional (but still recommended, because it's faster and more awesome).
But this reduces the list of mandatory requirements.
Next one on my list ist #attrs (I’m sorry, @hynek 🙈).
With modern Pythons, TS will than have zero mandatory dependencies (and only tomli on oder Pythons). This should make it more attractive for projects like #pytest to adopt it. 🙂
After watching Brandt Bucher's PyCon talk on the new 3.11 specializing interpreter, I played around with looking at #cattrs generated functions and how they specialize.
Nothing special there, but I discovered something else. At least on #python 3.11, functions with kw-only params (so, `*` in the arg list before params with defaults) are significantly slower (~10%) than functions with just positional params.