Python 3.x supports (optional) function annotations:
def add_ints(x:int, y:int) -> int :
return x+y
I sometimes encounter problems as to how to represent a given "type" can be represented, and this time, I have a function that returns a generator:
def myfunc(x: [int]) -> "generator that returns ints":
# ^~~~~~~~~~~~~~~~~~~~~~~~~~
return (n for n in x if n%2 == 0)
How should I annotate the return value? Is there any reference I can consult to?
-> generator(int)
without making it a string.int
s (Python's generators can return multiple types anyway). If you are just doing this for your own type-checking I don't see any reason not to use a string identifier or maybe a global variable.types.GeneratorType
seems to be what I was looking for (Why didn't I search for that!). Thanks for suggesting using string or variables too, I just wasn't certain it can be acceptable at all. Will you spare some more time and post that as an answer, so that I can accept it?