aiodataloader
aiodataloader copied to clipboard
Type annotations for DataLoader
I just started experimenting with aiodataloader
and it's been great so far. Having type annotations (at least for the public DataLoader
class) would make it even easier for folks who are leveraging Python's typing system.
From a preliminary look it seems like adding the basics for the DataLoader
would be pretty straightforward. We would need to accept a type for the KeyType
and ValueType
. I think it would look something like
from aiodataloader import DataLoader
class UserLoader(DataLoader[int, User]):
async def batch_load_fn(self, keys: Sequence[int]) -> Sequence[User]:
return await my_batch_get_users(keys)
user_loader = UserLoader()
I may have some time to try doing this myself. If I do would you be interested in accepting the patch?
@allancaffee, I've already done work to implement typing on top of aiodataloader. How about I get a PR done in the next week or two, and you can take a look?
Hello guys, type annotations for aiodataloader would be really good. I am facing some issues with mypy at the moment. I think having type annotations would be very useful.
Any updates on this? @markedwards if you PR your initial changes I might be able to contribute to this 🙂
I took a stab at it: https://github.com/syrusakbary/aiodataloader/pull/25
That PR has some commentary about its limitations, if anyone has any quick knowledge that could overcome those limitations I'm happy to put in the grunt work implementing corrections.
@aawilson in case you're using graphene: we added the code of this library to the main graphene library, because the current maintainer seems to be inactive. Happy to discuss any issues there if you're willing to re-open your PR request there!
We aren't 😭, we're using Ariadne. But since I'm already here I can pull you guys down and resubmit to it, I can always backport any changes from that discussion
This repo is actually actively monitored and maintained, although it's a bit slow. I'm planning to take a look at the PR, but made an initial comment about formatting.
I'll see if I have feedback on the approach once I can look a bit deeper.
Following up here, @aawilson has a PR that is nearing completion, and will result in a fully-typed release of aiodataloader (I expect this to be 0.3.0).
@erikwrede, ideally graphene should switch back to using this library directly, since it is in fact maintained and we are moving forward now with improvements. What do you think?
Closing this, now that #25 is merged. I plan to do a typed release of aiodataloader in the coming days.