Demystifying python container types
Writing type annotations in python can be hard. How do I pick the right one with so many different options that look so similar? If a function returns [1, 2, 3], how should I annotate it? Should it be an Iterable, or a MutableSequence? Can it be a Generator? And why not just a list? The short answer is, as always, “it depends”, on what exactly you want to do. Let’s go through some of the python types related to container of elements, discuss how those are related, and where to use them.