Session Ready
Exercise

TextFile hints

In this exercise, we will go back to the example of a TextFile class that can represent any text file.

As in the previous chapter, TextFile stores file contents in an instance variable called text.

This time our TextFile class will have a get_lines() method that returns all of the lines from the text file used to instantiate the TextFile class.

The TextFile class definition is ready, but we want to add type hints, so that calling help() on the TextFile class will provide type annotation information to users.

To help getting things started, we've already imported the List class from the typing module.

Instructions
100 XP
  • Add type hints to the __init__() method's name argument.
  • Add type hints to the get_lines() method's return value.