avatar Bite 369. Advanced Type Hints

In the previous Bite you have started annotating code with basic type hints, using the built-in data types. In this Bite, you are going to use type classes from the typing module to annotate variables that go beyond the basic data types.

If you are new to typing / type annotations, maybe you want to read the Pybites article series about typing first or in an addition to this learning path. Of course, you can always ask the official documentation for help, though. There is the documentation of the typing module (be aware of the correct Python version that you are using!) as well as a lot of Python Enhancement Proposals (PEP), also linked in the module's documentation. Given that the official documentation, and PEPs in particular, are often not the easiest reading material, I found the mypy documentation a very good starting place.

Your Task

In this Bite, you have to add type hints to all 6 functions. Make sure you annotate both the function's parameters as well as the return type of each function. The function's docstring should tell you the critical information you need to decide with type hint to use for the parameters. The return value has to be inferred by you.

Noteplease be patient if the platform does not instantly show the test results, the last final test (test_mypy_report) takes at least 10 seconds to run. However, in return we are not limited to checking concrete types, allowing multiple options in your code submissions. Thanks. 

Login and get coding
go back Intermediate level
Bitecoin 3X

26 out of 28 users completed this Bite.
Will you be Pythonista #27 to crack this Bite?
Resolution time: ~44 min. (avg. submissions of 5-240 min.)

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help