@@ -29,20 +29,64 @@ def __init__(self, parent: "BaseSource") -> None:
2929 async def update (self , record : Record ):
3030 """
3131 Updates a record for a source
32+
33+ Examples
34+ --------
35+ >>> async def main():
36+ ... async with MemorySource(records=[]) as source:
37+ ... # Open, update, and close
38+ ... async with source() as ctx:
39+ ... example = Record("one", data=dict(features=dict(feed="face")))
40+ ... # ... Update one into our records ...
41+ ... await ctx.update(example)
42+ ... # Let's check out our records after calling `record` and `update`.
43+ ... async for record in ctx.records():
44+ ... print(record.export())
45+ >>>
46+ >>> asyncio.run(main())
47+ {'key': 'one', 'features': {'feed': 'face'}, 'extra': {}}
3248 """
3349
3450 @abc .abstractmethod
3551 async def records (self ) -> AsyncIterator [Record ]:
3652 """
3753 Returns a list of records retrieved from self.src
54+
55+ Examples
56+ --------
57+ >>> async def main():
58+ ... async with MemorySource(records=[Record("example", data=dict(features=dict(dead="beef")))]) as source:
59+ ... async with source() as ctx:
60+ ... async for record in ctx.records():
61+ ... print(record.export())
62+ >>>
63+ >>> asyncio.run(main())
64+ {'key': 'example', 'features': {'dead': 'beef'}, 'extra': {}}
3865 """
3966 # mypy ignores AsyncIterator[Record], therefore this is needed
4067 yield Record ("" ) # pragma: no cover
4168
4269 @abc .abstractmethod
4370 async def record (self , key : str ):
4471 """
45- Get a record from the source or add it if it doesn't exist
72+ Get a record from the source or add it if it doesn't exist.
73+
74+ Examples
75+ --------
76+ >>> async def main():
77+ ... async with MemorySource(records=[Record("example", data=dict(features=dict(dead="beef")))]) as source:
78+ ... # Open, update, and close
79+ ... async with source() as ctx:
80+ ... example = await ctx.record("example")
81+ ... # Let's also try calling `record` for a record that doesnt exist.
82+ ... one = await ctx.record("one")
83+ ... await ctx.update(one)
84+ ... async for record in ctx.records():
85+ ... print(record.export())
86+ >>>
87+ >>> asyncio.run(main())
88+ {'key': 'example', 'features': {'dead': 'beef'}, 'extra': {}}
89+ {'key': 'one', 'extra': {}}
4690 """
4791
4892
0 commit comments