cattrs icon indicating copy to clipboard operation
cattrs copied to clipboard

Recipes for initializer selection

Open AdrianSosic opened this issue 5 months ago • 3 comments

Hi @Tinche,

here's a first draft for the "Recipes" page you suggested in #489. Let me know what you think and what needs to be adapted. Of course feel free to adjust examples and text as you like.

BTW: Should we add some tests for the recipes, or is there some automatic doc testing already in place (haven't yet looked too much into the repo mechanisms, tbh).

AdrianSosic avatar Feb 01 '24 10:02 AdrianSosic

I like it!

Do you think we should export StructureHook (and UnstructureHook) from cattrs directly?

Should we add some tests for the recipes

You can use doctests. See an example here: https://github.com/python-attrs/cattrs/blob/3c4572fd28e587c02c1112904c981ff3a6c3801c/docs/customizing.md?plain=1#L68. You can run them using make doctests, and they get run on RTD when the docs get built. If they fail they stop the build, making someone take a look.

Also, I've been trying to use semantic newlines for docs, like attrs: https://github.com/python-attrs/attrs/blob/main/.github/CONTRIBUTING.md#documentation. In practice, this means lines break not based on line length but a natural break (like a comma).

Tinche avatar Feb 11 '24 14:02 Tinche

Hi @Tinche,

you mean making StructureHook and UnstructureHook available directly from the high-level cattrs namespace? I think that sound like a good idea. Would make it easier for people who prefer to annotate their hooks (like me 🙃).

I've tried my best to incorporate the requested changes. Was not 100% sure about the semantic newlines but tried to follow the style from the other .md files in the docs folder.

Let me know if you see other things that require changes (e.g. concerning the hook imports mentioned above). Otherwise, this PR is ready from my side 👌🏼

AdrianSosic avatar Feb 19 '24 09:02 AdrianSosic

you mean making StructureHook and UnstructureHook available directly from the high-level cattrs namespace

Yeah, exactly.

In any case, great work. I might do an editing pass before releasing the next version.

Tinche avatar Mar 01 '24 11:03 Tinche

Hi @Tinche, I saw the PR is now merged. Nice, thanks 🙏 Unfortunately, the code sections are not displayed properly, probably due to me messing with doctest and selecting the wrong label (sorry, have not worked with that plugin so far). Could you do me a favor and fix that part, since I'm currently traveling and have no PC with me for the next couple of weeks? Thanks and Cheers ✌️

AdrianSosic avatar Mar 06 '24 19:03 AdrianSosic

Fixed it! Looks like doctest blocks don't do syntax highlighting unless they are written in the prompt style :/

Tinche avatar Mar 07 '24 11:03 Tinche

Hm, seems inconvenient... but thanks for the fix anyway!! ✌️

AdrianSosic avatar Mar 07 '24 14:03 AdrianSosic