Skip to content
Advertisement

Tag: single-dispatch

Does python functools.singledispatch work with Generator type?

I extended the example at https://docs.python.org/3/library/functools.html#functools.singledispatch by adding a registration for generator type while it works with list, it doesn’t seem to work with generator with error like Is it expected that singledispatch does not work with generator? Answer typing.Generator is a type hint, not a type. You need types.GeneratorType. Objects are not considered instances of type hints according to

Advertisement