python-novice-gapminder
python-novice-gapminder copied to clipboard
Include Python annotations in Lesson 18
While there is no need in Python to indicate the type of a variable when declaring it, it is incredibly useful as a hint for what the expected type of a variable is gong to be, especially in functions. Most big Python packages like Numpy or Pandas have their functions annotated, and many Python IDEs use this information to help the coder to use those functions. It is described in PEP 3107.
This is material that can easily fit on a very short time (5-10 min, tops) in Lesson 18 on Programming Style, and it is something that will certainly contribute to make the code more readable. I would restrict it to annotating functions inputs and outputs, which I find most useful, not every single thing - although I would mention it can be done.
The contents of that section could be:
- Using the typing package
- What things can be annotated
- Annotating variables that can have different types
- Annotating functions that have other functions as inputs
- Functions signatures
If this seems useful, I'm happy to create the content myself and open a PR.
I'm in favor of this as I like to use the type annotations as well. Introducing the typing
package could end up being a big rabbit hole though..
I wonder if we could introduce the ideas of type annotations and only provide a link to the typing
package for those interested in more details. I guess this wouldn't work since I think we have example functions that take lists as inputs and thus we need to import from the typing
package.