#cattrs — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #cattrs, aggregated by home.social.
-
Got #cattrs coverage up. However, it's just statement coverage, not branch coverage; that'll have to wait a while.
-
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 thingsit 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.
-
#cattrs depends on the `immutables` package for a subset of its tests. `immutables` 0.19 doesn't support 3.12, `immutables` 0.20 doesn't support 3.7, cattrs supports both. How boned am I?
-
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.
-
My first PR to #cattrs after the release was switching from Poetry to PDM. 🤞
-
#cattrs 23.1.0 is out (fingers crossed I didn't mess anything up 🤞 )
Instead of the usual thread, I'm trying something new. I've written up a blog post with the changes: https://threeofwands.com/intro-to-cattrs-23-1-0/
Happy cattrsing! #python
-
So #cattrs 23.1.0 is ready to roll out, and I've written an accompanying blog post going over the major features.
But since I'm about to hit the seaside for an extended weekend that'll have to wait until Tuesday. In the meantime, you can install the RC I just published and give it a test: https://pypi.org/project/cattrs/23.1.0rc0/
-
Ok, so while at PyCon a nice person in our open space used Midjourney to generate a bunch of potential #cattrs logos. I picked one that I like, but I do need it tweaked so it looks good on both light and dark backgrounds.
I'm obviously prepared to pay for this, but where do I find someone willing to do it in the first place? Places like Fiverr?
-
I'm getting ready to release the next version of #cattrs, and it has a lot of stuff in it. Usually I'd do a long-ish Fediverse/Twitter thread but I'm thinking there has to be a better way.
Do I write a blog post about it? Do I write an elaborate Github release page? Do I add a page to the actual project docs for the release?
The idea is to introduce folks to the new features and give some context and examples.
Suggestions welcome.
-
@hynek I need an opinion on an API decision for #cattrs.
When structuring some data that's been typed as `typing.Any`, cattrs won't change it - it gets assigned the source value without any transformation. But what should cattrs do when unstructuring an `Any` field? Pass it through as well, or actually unstructure it according to its runtime type?
For example, if an `Any` field holds an attrs instance, would you expect the result to be a dict or that instance, unchanged?
-
Just posted a Stack Overflow answer on how to use `typing.Annotated` with #cattrs: https://stackoverflow.com/questions/74383981/serialising-with-cattrs-and-want-to-omit-field-x1-string-field/74410692#74410692