3 ms·
I dont't know, I have the opposite experience. In Python you can have a function that returns a certain object `Publication` most of the time. But sometimes it
by captainmuon 4y ago
I dont't know, I have the opposite experience. In Python you can have a function that returns a certain object `Publication` most of the time. But sometimes it returns a slightly different object `MyPublication`. This doesn't have to be due to bad design, maybe it comes from some library function and you didn't even notice. Due to duck typing it will work (until you do something with the result that only one version supports). Then sometimes you will return None, and sometimes "[something]".
Type annotations are really valuable to ensure that your types are actually what you think they are. In the same spirit of using assertations for pre and post conditions.
- nine_zeros 4y agoWhat you are enjoying is called a good type system, not Python's type annotation specifically. The comparison is with other typed/type-hinted languages, not with Python 2.7.