Question

I've been playing with Typscript for a while now, and I gotta say, bundled with the fact that nodejs is faster than the current implementation for CPython for my web development needs, I've been more inclined to make more things with it.

In fact, I've made a couple of basic apps with it, even for desktop. What I love about Typescript is the fact that is has optional static types. This makes coding often a lot easier, and not to mention the intellisense is amazing for when you want to code quickly and get a prototype running. I've encountered fewer bugs in the development process as well.

But here lies the problem, I've been working with Python for a year now, and I love the language, and I am just more used to the syntax. However, more and more, I see that optional static typing can be an awesome plus point for Python. So, I did a bit of research, I first started with trying to understand what the situation of static typing is right now. Just like anyone else, I used a search engine to find out.

These are some of the sources of information that I've read through:

  1. Adding Optional Static Typing to Python

If you take a look at the implementation here (excerpt from the link above):

from StringIO import StringIO

def foo(f: StringIO) -> str:
    f.write("hello")
    return f.getvalue()

f1 = StringIO("booh+")
print foo(f1)  # prints "booh+hello"

Now, this looks like very similar to the implementation in Typescript. However, if you take a look at the date, it goes back all the way to 2004.

Then, I took another look at a slide that the BDFL, Guido made:

  1. Why Add Static Typing?

Again, you see the same rhetoric. However, I've not been able to find any new information regarding this.

I've also taken a look @ this SO answer on enforcing static types.

So, I wanted to ask, what is the situation or state of adding optional static typing in Python? Or do we need to invent something like Typescript but for Python 3?

I believe that optional static typing is important, because in my own very limited experience, I've seen that something like Typescript and C# work better since when making complex classes or making large projects, I've seen that static typing has gone a long way to helping me write code faster and error free. I am sure I'm not nearly as good as most of the developers here, but that's my take. This is why I feel that this question is an important one. I mean if you had the optional typing of a language like C# with the beautiful syntax that Python provides, then Python would probably be unstoppable (yay!).

I've done some research into this, but I got nothing substantive, so I was hoping that some of the awesome and wise members of SO would shed light on this issue.

Was it helpful?

Solution

Or do we need to invent something like Typescript but for Python 3?

That's mypy !!! :-)

Personally, I think either they are going to merge or Python is going to come up with their own solution. Hope this happens very soon!!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top