Skip to content Skip to sidebar Skip to footer

Do Python Parameter Type Hints Support Nested Type Information?

I have a function that is logically as follows: def computeProbability( x_i: np.array(np.int32), colProbabilities: list(dict(string,np.float32)) ) -> list(double):

Solution 1:

Actually it is possible to give deep type information. Just discovered type hints from python 3.5+. These are great for IDE's: e.g. you can do this

ListOfDict = List[Dict[str, float]]

then declare a method that returns a list of Dicts with string key and float value

from typing importList, Dict
Vector = List[float]
ListOfDict = List[Dict[str, float]]

Using this:

defcomputeLikelihood(x_i_vals: Vector, allProbs: ListOfDict):

Now we can get method hints in the IDE!

enter image description here

This is a big win for developing nested data structures!

Post a Comment for "Do Python Parameter Type Hints Support Nested Type Information?"