|Python Language Summit 2020 - Python Typing|
|Written by Mike James|
|Saturday, 02 May 2020|
Python Summit has gone virtual for obvious reasons. There are lots of interesting talks, but the one that piqued my interest was on the gradual addition of gradual typing to Python. I was going to call the news "Python typing considered harmful", but then I thought better of it.
I really didn't want to bring the hounds of html down on myself, but let Guido van Rossum enlighten you:
"There are a lot of PEPs about typing!" said Guido van Rossum at the Language Summit. Since 2014 there have been ten PEPs approved for Python's type-checking features. Two of them have been approved already this year: the relatively "esoteric" PEP 613: Explicit Type Aliases, and another that will have widespread impact, PEP 585: Type Hinting Generics In Standard Collections, written by Łukasz Langa and mainly implemented by van Rossum."
Notice the use of the term "esoteric" - it sounds as if Guido isn't a true believer at the bottom of it.
The nice thing about Python is that you can avoid typing altogether, but if you do feel guilty about it you can use optional typing. This seems easy at first and even rewarding.
What could be wrong with specifying the signature of a function? But then the rot sets in. Things get complicated. You have to invent how to type complicated things like functions as a whole or data structures. You have invent generics and that's not easy and then there is the whole issue of covariance and contravariance. All tough to understand and hard to get right.
it quickly goes from a fun game with ints to a nightmare with:
Python type annotations don't actually do anything unless you run a type checker, mypy for example, so I suppose they are not that restrictive. But that just makes using them even less useful.
Python seems to be accumulating type annotation like a rock gathers moss.
"Yury Selivanov noted that typing.Optional[t] could be replaced with t | None, and asked whether it could be shortened further as t?. "Every year," replied Van Rossum, "there's another feature that people want to use the question mark for." In his opinion, t | None is convenient enough, and another syntax would be redundant. "
Good job Guido is still there to limit its spread. When asked about progress on typing, he said that he had moved on to retirement and that the Python static mailing list needed more people to join.
I write fairly big Python programs and I can honestly say that I have never had an error that strong typing would have helped me find or stopped me from making. I know I'm expressing a minority view, but I think the Python type annotation experience is evidence that the minority might have a point.
This is an account of the talk written by A. Jesse Jiryu Davis from which all the quotes come from. Do read the account - it has much more to say than covered in this news item.
or email your comment to: email@example.com
|Last Updated ( Saturday, 02 May 2020 )|