Python history: origin of the arrow annotation

I was curious how and why return annotations use the arrow `->` symbol, so I went spelunking into the depths of the Python-Ideas and Python-Dev mailing lists. Much to my surprise, I couldn't find any discussion or debate about it. Eventually I tracked the discussion back to a mailing list I didn't even know existed, Types-Sig, all the way back to 13th Dec 1999, where I found this email by Tim Hochberg: https://mail.python.org/pipermail/types-sig/1999-December/000281.html suggesting the arrow symbol for all type declarations. This appears to be the first suggestion of the arrow symbol for type annotations in Python. I am surprised that type checking was being discussed so long ago. Python was not even a decade old, and if my calculations are correct, the versions at the time would have been 1.5.2 and 1.6.0. But I am especially amazed that the choice of symbol seems to have been accepted with very little argument or debate about alternative colours for the bike-shed. I can't find any suggestions for alternative symbols such as `=>` `-->` `==>` `->>` etc, and very little for keywords such as `as`. The day after Tim posted, Tony Lownds suggested `as` and then immediately suggested using Tim's arrow symbol for the return type only: https://mail.python.org/pipermail/types-sig/1999-December/000335.html and then as far as I can tell, we've never looked back. If there is anyone whose memory reaches back that far, does that sound right? -- Steve

Good question. I don't think anyone has ever asked this before... Given the variants you propose, I'd say that the 3-character ones would be more effort to type without real benefits, and `=>` would at the time (and perhaps still :-) be seen as too close to `>=`. Could it be that there were already other languages using `->` for return types? I do know that we needed something there -- from the start I was a fan of `x: int` because it's the same as Pascal (the language I used most intensely in college), and if it had been syntactically possible I would have used 'def f(): int' for the return type as well, but the LL(1) parser in use in 1999-2000 would interpret that as a very short function body. It's also possible that it comes from the `->` operator in C, which would be the only "ASCII art arrow" that I was familiar with at the time. Note that a slide deck I presented in 2000 on the topic still exists: https://gvanrossum.github.io/static-typing/ This shows something pretty close to the modern notation for function and variable annotations, but with a `decl` keyword thrown in. On Fri, Mar 5, 2021 at 3:08 AM Steven D'Aprano <steve@pearwood.info> wrote:
I was curious how and why return annotations use the arrow `->` symbol, so I went spelunking into the depths of the Python-Ideas and Python-Dev mailing lists.
Much to my surprise, I couldn't find any discussion or debate about it.
Eventually I tracked the discussion back to a mailing list I didn't even know existed, Types-Sig, all the way back to 13th Dec 1999, where I found this email by Tim Hochberg:
https://mail.python.org/pipermail/types-sig/1999-December/000281.html
suggesting the arrow symbol for all type declarations. This appears to be the first suggestion of the arrow symbol for type annotations in Python.
I am surprised that type checking was being discussed so long ago. Python was not even a decade old, and if my calculations are correct, the versions at the time would have been 1.5.2 and 1.6.0.
But I am especially amazed that the choice of symbol seems to have been accepted with very little argument or debate about alternative colours for the bike-shed. I can't find any suggestions for alternative symbols such as `=>` `-->` `==>` `->>` etc, and very little for keywords such as `as`. The day after Tim posted, Tony Lownds suggested `as` and then immediately suggested using Tim's arrow symbol for the return type only:
https://mail.python.org/pipermail/types-sig/1999-December/000335.html
and then as far as I can tell, we've never looked back.
If there is anyone whose memory reaches back that far, does that sound right?
-- Steve _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/4ZZP5DJA... Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>

On Fri, 5 Mar 2021 16:45:25 -0800 Guido van Rossum <guido@python.org> wrote:
Good question. I don't think anyone has ever asked this before... Given the variants you propose, I'd say that the 3-character ones would be more effort to type without real benefits, and `=>` would at the time (and perhaps still :-) be seen as too close to `>=`.
Could it be that there were already other languages using `->` for return types? I do know that we needed something there -- from the start I was a fan of `x: int` because it's the same as Pascal (the language I used most intensely in college), and if it had been syntactically possible I would have used 'def f(): int' for the return type as well, but the LL(1) parser in use in 1999-2000 would interpret that as a very short function body.
It's also possible that it comes from the `->` operator in C, which would be the only "ASCII art arrow" that I was familiar with at the time.
Note that nowadays you can use `->` to denote function return types in C++ (that was not the case in 1999, though). It's also the only allowed style for anonymous functions ("lambdas"): https://en.cppreference.com/w/cpp/language/function https://en.cppreference.com/w/cpp/language/lambda Regards Antoine.

Haskell and the MLs are older than I am and use "->" to mark their function types (their functions are curried, but it clearly counts). Given the overall influence functional languages have had on modern typing, their influence making itself felt here would be unsurprising. On Sat, 6 Mar 2021 at 07:47, Antoine Pitrou <antoine@python.org> wrote:
On Fri, 5 Mar 2021 16:45:25 -0800 Guido van Rossum <guido@python.org> wrote:
Good question. I don't think anyone has ever asked this before... Given the variants you propose, I'd say that the 3-character ones would be more effort to type without real benefits, and `=>` would at the time (and perhaps still :-) be seen as too close to `>=`.
Could it be that there were already other languages using `->` for return types? I do know that we needed something there -- from the start I was a fan of `x: int` because it's the same as Pascal (the language I used most intensely in college), and if it had been syntactically possible I would have used 'def f(): int' for the return type as well, but the LL(1) parser in use in 1999-2000 would interpret that as a very short function body.
It's also possible that it comes from the `->` operator in C, which would be the only "ASCII art arrow" that I was familiar with at the time.
Note that nowadays you can use `->` to denote function return types in C++ (that was not the case in 1999, though). It's also the only allowed style for anonymous functions ("lambdas"): https://en.cppreference.com/w/cpp/language/function https://en.cppreference.com/w/cpp/language/lambda
Regards
Antoine.
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/K75WNUFD... Code of Conduct: http://python.org/psf/codeofconduct/

On Fri, 5 Mar 2021, 9:10 pm Steven D'Aprano, <steve@pearwood.info> wrote:
I was curious how and why return annotations use the arrow `->` symbol, so I went spelunking into the depths of the Python-Ideas and Python-Dev mailing lists.
Much to my surprise, I couldn't find any discussion or debate about it.
If you haven't already, also try to track down any PEP 3107 discussions on the python-3000 mailing list. I don't actually recall any major debate over the syntax of function annotations though - the only controversy I can recall was over whether or not it was a good idea to add the syntax before we had a solid plan for the standard associated semantics. Cheers, Nick.
participants (5)
-
Antoine Pitrou
-
Guido van Rossum
-
Nick Coghlan
-
Shantanu Jain
-
Steven D'Aprano