NLeSC / guide

Software Development Guide
https://guide.esciencecenter.nl
Creative Commons Attribution 4.0 International
47 stars 30 forks source link

add Python type hints #359

Open egpbos opened 1 month ago

egpbos commented 1 month ago

Added a subsection on type hints, following the discussion in #310. Also added a few cool libraries, e.g. FastAPI that was mentioned by Bouwe in #54 and Typer from the same author.

Fixes #310.

Checklist

SIGNIFICANT changes / additions, e.g. new chapters

ALL contributions

egpbos commented 2 days ago

@stefsmeets We talked today about attrs and how you used it for nested-yaml / dataclass validation and preferred it over Pydantic. In this PR, I happened to add a bit of text on Pydantic. I haven't looked at attrs yet, but do you think it makes sense to mention it in here as well? Or does it deserve a topic of its own? Is schema / data validation perhaps a useful topic for a section of the data chapter?

stefsmeets commented 2 days ago

I think it makes sense, I find attrs to be much more approachable than pydantic. The attrs docs have a really nice section on comparing the different tools: https://www.attrs.org/en/stable/why.html

egpbos commented 2 days ago

Briefly browsing PROTEUS' use of attrs, it seems like a nice lightweight tool for value validation. I'm not sure how (or even if) Pydantic handles this, but certainly seems useful. I don't think it should go under this PR, though, it's a topic independent of type hints.

egpbos commented 2 days ago

Whoops, missed your comment @stefsmeets before posting mine just now. Agree, it looks nice and lightweight. Lets make a separate issue.