[Python-ideas] Proposal: Use mypy syntax for function annotations
Rock Neurotiko
miguelglafuente at gmail.com
Fri Aug 22 09:47:34 CEST 2014
First, sorry for my (probably) bad english :)
I think that everyone who wants to learn about types, type system, what is
static type, what is not, why function annotations (or some other, but I
prefer it) refering to types is being proposed, should learn a little bit
(you won't regret!)
1) This article (What to know before debating type systems) has been sent
before in this thread (I think) but is a must read:
http://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/
2) Bob's talk in Europython last month "What can python learn from haskell"
at least until minute 20, that talks about this things.
http://pyvideo.org/video/3046/what-can-python-learn-from-haskell
3) If you love maths, some book of Benjamin C. Pierce (about type systems,
of course!), this three are so good (but hard). Ordered from low to high
level.
- Type Systems for programming languages.
- Types for programming languages.
- Advanced topics in Types and programming languages.
4) If want to learn more, search in google, there are so much
books/articles about types, and if you can learn about haskell types (or
Idris if you are crazy), better ;)
As last word, I want to give my opinion about the proposal.
I like the proposal, and I would love to see it in Python 3.x, I don't
think that function notations can have a better purpose.
Of course, what is being proposed won't be needed to run a python program,
and you will still can write your function notations whatever you want, but
have a standard proposal will help a lot to build tools that read the
function notations (like IDEs, linters, static type checkers, ...)
About the syntax, I love the mypy's syntax, and remember me a lot to other
languages like scala.
def primes_to_n(n: Int) => List[Int]
def primes_to_n(n: int) -> List[int]
This two function definitions are a function that get an int and return a
list of integers. First definition is Scala, second one is Python with
mypy's syntax.
I like much more the Haskell syntax, but is another world and I think that
python shouldn't have a syntax like that:
primes_to_n :: Int -> [Int]
About other syntax that I had seen in this thread:
- decorators: I really don't like that one, is compatible with python 2,
ok, but looks so bad (to me)
- docs: That's not bad at all, and can still exist with the typing syntax
to declare the types, but we have function annotations where the types are
much close to the definition, and that's definitively good.
- PyContracts: That's not bad at all, but just for check types in runtime,
much things (the main diferences with mypy) can't be done in static, for
example, how you know if this will work *before* execute it:
@contract
def f(x: 'list[3>](str)') -> 'list(str)'
f(input().split(" "))
That's a function that take a list of three or more strings, and is called
with the user input.
You can't know if that list will be over three elements if you don't run it
and get the input, and even those, you can't say that will be true all the
times you execute it.
That's just my opinion :)
Cheers!
--
Miguel García Lafuente - Rock Neurotiko
Do it, the devil is in the details.
The quieter you are, the more you are able to hear.
Happy Coding. Code with Passion, Decode with Patience.
If we make consistent effort, based on proper education, we can change the
world.
El contenido de este e-mail es privado, no se permite la revelacion del
contenido de este e-mail a gente ajena a él.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140822/bf807fda/attachment.html>
More information about the Python-ideas
mailing list