Author phr
Recipients docs@python, gvanrossum, phr, rhettinger, veky
Date 2019-10-03.03:38:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1570073914.88.0.362848840236.issue38333@roundup.psfhosted.org>
In-reply-to
Content
abs takes any value that understands the __abs__ method and returns something of the same type.  In fact there is already a type protocol for it:

https://mypy.readthedocs.io/en/stable/protocols.html#supportsabs-t

So abs's signature would be (x : Abs[T]) -> T where T is a type parameter.  

I'm sure there are some examples where no good signature is possible, but lots of others are fine.  Someone did a Smalltalk study long ago and found that most functions were monomorphic in practice even though Smalltalk is dynamically typed like Python.  As a matter of style, Python code tends to be typed even when it doesn't have to be.  Not all the time of course.

I'm still getting used to types and mypy (I was a py2 holdout til quite recently, and mypy has been a more attractive reason to change than any of the other stuff) and I do keep noticing cases that don't work as I hoped, but it's still a good move in general.
History
Date User Action Args
2019-10-03 03:38:34phrsetrecipients: + phr, gvanrossum, rhettinger, docs@python, veky
2019-10-03 03:38:34phrsetmessageid: <1570073914.88.0.362848840236.issue38333@roundup.psfhosted.org>
2019-10-03 03:38:34phrlinkissue38333 messages
2019-10-03 03:38:34phrcreate