Strong typing implementation for Python

Matt Wheeler m at funkyhat.org
Sun Oct 11 15:45:37 EDT 2015


On 9 October 2015 at 17:26, John Michael Lafayette
<johnmichaelreedfas at gmail.com> wrote:
> I would like Python to have a strong typing feature that can co-exist with
> the current dynamic typing system. Currently Python is like this:
>
>     var animal = Factory.make("dog")  # okay.
>     var dog = Factory.make("dog")       # okay.
>     var cat = Factory.make("dog")        # are you sure?
>
> I would like Python to also be able to also do this:
>
>     Animal a = Factory.make("dog")    # okay. Dog is Animal.
>     Dog d = Factory.make("dog")         # okay. Dog is Dog.
>     Cat c = Factory.make("cat")           # Runtime error. Dog is not Cat.

Though it's intended for performance optimisation rather than simply
static typing for static typing's sake, you could probably use Cython
to achieve what you want...

...but then you might start to see the benefits of dynamic typing :)


-- 
Matt Wheeler
http://funkyh.at



More information about the Python-list mailing list