Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_many()? #14

Closed
hynek opened this issue Aug 4, 2023 · 2 comments · Fixed by #15
Closed

get_many()? #14

hynek opened this issue Aug 4, 2023 · 2 comments · Fixed by #15

Comments

@hynek
Copy link
Owner

hynek commented Aug 4, 2023

As @glyph mentioned to me, having many services can get unnecessarily verbose and even slow.

We should consider:

db, web_api, working_q = svcs.get_many(Database, WebAPI, WorkingQueue)

It's still a for loop, but saves boilerplate and reduces business code from 3 lines to 1.

Better names appreciated.

@glyph
Copy link

glyph commented Aug 4, 2023

… just give .get an @overload? It's a little ugly type-wise, but you can easily make

db = svcs.get(Database)
# or 
db, web_api = svcs.get(Database, WebAPI)

(I would not blame you for finding the single-element special-case kind of gross, but I think as a user this is what I'd want)

@hynek
Copy link
Owner Author

hynek commented Aug 4, 2023

Hmmm, so there's been thought of allowing to pass arguments to factories, but we totally could just say kwargs only and posargs are always the getter. 🤔

What do you mean by "ugly type-wise"? Will I have to send @Tinche to the typing salt mines or is does it just look ugly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants