Sep-19-2021, 06:06 AM
from collections.abc import Generator from typing import Generator as TypingGenerator from inspect import isgeneratorfunction, isgenerator def foo(): """Function""" def bar(): """Generatorfunction""" yield print("foo", isgeneratorfunction(foo)) print("bar", isgeneratorfunction(bar)) print("foo()", isgenerator(foo())) print("bar()", isgenerator(bar())) # Generator could not detect a Generatorfunction # but a Generator print("bar()", isinstance(bar(), Generator)) print("bar()", isinstance(bar(), TypingGenerator))I'm not sure about typing.Generator. It detects a generator, but typing is used for type hints, which is used for IDEs and Code Linters. One question, many solutions...
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!