Live data from Hacker News

Mypy - An experimental Python variant with dynamic and static typing

mypy-lang.org

11–20 of 42 posts

Re: Mypy - An experimental Python variant with dynamic and static typing

#11

> Mypy will get rid of the Global Interpreter Lock (GIL) >Details of the concurrency model are still undecided, though Wait, what? There have been numerous attempts to get rid of the GIL, most of which failed miserably. A promise to get rid of the GIL without even deciding on a concurrency model seems a little premature.

This is not true. There have been plenty of successful attempts to remove the GIL, including from CPython. It's not impossibly hard to do so by a long shot.

The GIL is an optimization though, and so the performance hit from removing it on single threaded code is prohibitive. You can watch any of David Beazley's talks on the GIL for more info.

Re: Mypy - An experimental Python variant with dynamic and static typing

#13
I've been thinking about this for a while: the benefit of static typing doesn't really come from being compile-time, it comes from making sure the causes of a certain category of errors must be local to the function where the error's seen. I suspect that a run-time static typing framework, which simply did the equivalent of asserting the type of any variable whenever it was assigned, would provide almost all of the safety/development advantages of compile-time typing, and be much easier to implement for python.

Has anything like this been attempted?

Re: Mypy - An experimental Python variant with dynamic and static typing

#14
post #10

Whats the benefits of this over cython?

From the FAQ:

How is mypy different from Cython?

Cython is a variant of Python that supports compilation to efficient C modules. Mypy differs in the following aspects, among others:

Mypy will have a powerful type system that can detect many type errors while supporting a very Python-like programming model. Cython has simpler types that primarily serve to speed up code.

Mypy will be able to speed up most programs, even programs that heavily use object-oriented features. Cython is primarily focused on speeding up numerical code and tight loops.

Mypy will have new virtual machine that allows speeding up all parts of the VM, including standard libraries and the garbage collector. Cython uses the normal Python VM.

Cython supports accessing C functions directly and many features are defined in terms of translating them to C. Mypy is not bound to any particular target language and can support both C and Java backends, for example. However, accessing C library functionality in mypy will not be as easy as in Cython.

Re: Mypy - An experimental Python variant with dynamic and static typing

#15
post #13

I've been thinking about this for a while: the benefit of static typing doesn't really come from being compile-time, it comes from making sure the causes of a certain category of errors must be local to the function where the error's seen. I suspect that a run-time static typing framework, which simply did the equivalent of asserting the type of any variable whenever it was assigned, would provide almost all of the s…

Dylan, Common Lisp, Dart, many others.

Re: Mypy - An experimental Python variant with dynamic and static typing

#16

> Mypy will get rid of the Global Interpreter Lock (GIL) >Details of the concurrency model are still undecided, though Wait, what? There have been numerous attempts to get rid of the GIL, most of which failed miserably. A promise to get rid of the GIL without even deciding on a concurrency model seems a little premature.

This is not true. There have been plenty of successful attempts to remove the GIL, including from CPython. It's not impossibly hard to do so by a long shot. The GIL is an optimization though, and so the performance hit from removing it on single threaded code is prohibitive. You can watch any of David Beazley's talks on the GIL for more info.

I stand corrected. Still, saying they are going to remove the GIL without addressing the challenges faced by other people who did the same - most notably the performance hit - makes me skeptical as to their ability to fulfill their promises.

Re: Mypy - An experimental Python variant with dynamic and static typing

#17

> Mypy will get rid of the Global Interpreter Lock (GIL) >Details of the concurrency model are still undecided, though Wait, what? There have been numerous attempts to get rid of the GIL, most of which failed miserably. A promise to get rid of the GIL without even deciding on a concurrency model seems a little premature.

This is not true. There have been plenty of successful attempts to remove the GIL, including from CPython. It's not impossibly hard to do so by a long shot. The GIL is an optimization though, and so the performance hit from removing it on single threaded code is prohibitive. You can watch any of David Beazley's talks on the GIL for more info.

Prohibitive is too strong I think. The patch to 1.4 discussed in a blog post by Beazley came with a 2x slow down, but that was an initial patch without much work on optimization. Besides that, I think 2x slowdown isn't that bad considering the language is not used for its raw efficiency anyway.

Re: Mypy - An experimental Python variant with dynamic and static typing

#19

> Mypy will get rid of the Global Interpreter Lock (GIL) >Details of the concurrency model are still undecided, though Wait, what? There have been numerous attempts to get rid of the GIL, most of which failed miserably. A promise to get rid of the GIL without even deciding on a concurrency model seems a little premature.

[deleted]

Re: Mypy - An experimental Python variant with dynamic and static typing

#20
How will mypy give satisfactory array and integer performance? In the case of arrays, unless they are homogeneous, you have to implement them as arrays of objects. And in the case of integers, they won't have the Python semantics unless they are the same number of bits as Python integers.

Also, what about things like metaclasses, changing methods of classes at runtime, etc? It seems like it won't be much like Python at all, and certainly not compatible, if it is to be efficient!

It seems to me that Python is fundamentally dynamic in nature, not just programatically, but also in terms of its type system.

Cobra was an attempt at a Python-like language with static compilation and type annotation. But so far, I don't see a mass exodus from Python to Cobra.

If mypy isn't going to be fully Python compatible, why wouldn't people who were unhappy with Python just switch to another statically typed/compiled language that already exists?

Post reply on HN