July 15, 2023, 4:49 a.m. | UponTheSky

DEV Community dev.to




Why Generators?


As previously announced, our journey starts from the discussion about Python generators. But why? To recapitulate, let’s write a very simple async function and see its execution result.



async def journey() -> None:
return 1

ret = journey()
print(type(ret))



<class 'coroutine'>
sys:1: RuntimeWarning: coroutine 'journey' was never awaited


Please ignore the warning for a bit. If it were a simple synchronous function(i.e. just the normal Python function), it would …

async coroutine function iterators journey network python simple type webdev

Data Engineer

@ Lemon.io | Remote: Europe, LATAM, Canada, UK, Asia, Oceania

Artificial Intelligence – Bioinformatic Expert

@ University of Texas Medical Branch | Galveston, TX

Lead Developer (AI)

@ Cere Network | San Francisco, US

Research Engineer

@ Allora Labs | Remote

Ecosystem Manager

@ Allora Labs | Remote

Founding AI Engineer, Agents

@ Occam AI | New York