Search code examples
pythonpython-typing

Function parameter: complex parameter structure understanding


 def resize_img( size: Tuple[int, int] = (299, 299)):
     pass

What does the parameter mean? I did not find the docs.


Solution

  • In case you are asking about Tuple[int, int]: this syntax is provided by typing module. It helps you and other people reading your code to understand which type should parameters have when passed into function. In your example - if you try to pass something different than tuple of two ints (i.e. resize_img(5)) IDE will mark it as Expected type 'Tuple[int]', got 'int' instead. This does not break code execution, but shows developer that probably he/she uses this function with wrong type of parameter passed in.