What is a good way to find the type of a more complex python object when trying to write statically typed python?
For example, I think I've got the type annotation of x correct here:
from itertools import combinations
from typing import Union, Iterator
x: Union[Iterator[tuple[int]]] = combinations([1,2,3], 2)
However I'd love to have figured out the type by doing something simple like this:
print(type(itertools.combinations))
<class 'itertools.combinations'>
But this gives the wrong result, i.e. <class 'itertools.combinations'>
is not Union[Iterator[tuple[int]]]
which I think is the correct type annotation here for x
.
In addition, PyCharm tells me that Union[Iterator[tuple[int]]]
is the correct type but when I click the documentation link it just gives me this which is the standard python docs for itertools and I can't see any type annotations there. So wondering if there's a way to access what PyCharm is doing under the hood here...