hynek / svcs

A Flexible Service Locator for Python.
https://svcs.hynek.me
MIT License
294 stars 19 forks source link

Document and test multiple factories per type #42

Closed hynek closed 1 year ago

hynek commented 1 year ago

fixes #40, fixes #41

Anything to add, @trendels?

trendels commented 1 year ago

Looks good! One minor thing: It turns out you don't strictly need the TypeAlias annotation. I was typing it out of habit (I like to be explicit about this so I can see at first glance if something is a module-level variable or a construct only used for type annotations). But Type checkers can also infer this (it doesn't do anything at runtime).

But since the audience for this documentation is not specifically Type Enjoyers (like me), you could shorten the example a bit by leaving it off. It type-checks as is and your users don't have to learn what a TypeAlias is.

hynek commented 1 year ago

Right! Also, NewType instead of Annotated should work too, no? I guess I’ll simplify Primary and make Secondary use NewType to cover both.

trendels commented 1 year ago

Yes, NewType also works! I hadn't thought about that. I like Annotated better because NewType is a bit cumbersome to use (having to type the name twice). But probably good to document both options.