Strong typing implementation for Python

Michael Torrie torriem at gmail.com
Sat Oct 10 20:38:32 EDT 2015


On 10/09/2015 10:26 AM, John Michael Lafayette 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?

No actually it's not like that at all.  Python's variables are not like
C where they are little boxes you can write values to.  Python's
variables are names that are attached to various objects.  Once a name
is assigned to an object, unless that object permits mutation to itself,
the actual value can never change, until the name is reused by rebinding
it.  On other words, Python's variables are very strongly typed.

Python does have type annotations, but those really only are meaningful
for function calls where the function can recommend some types of
variables to pass to it. And type annotations certainly have their place

Also, the nicest and most powerful feature of python is that as long as
my object supports a particular interface, I can pass it to a function
that knows nothing about my particular type and it works.  Called duck
typing.

Looks to me like you want Python to be Java.  Instead I suggest you
learn more idiomatic ways of doing things and let Python work for you
instead of against you.  But it sounds like you don't want Python
anyway.  If you want a static language, use a static language.  There
are many compiled languages available these days with vaguely
python-like syntaxes.  One is Nim.  There's the D language too for
bringing some of the expressiveness of Python to a language that's more
similar to C in syntax.  There's certainly room in the world for using a
variety of programming languages to suit your purpose.  For mine right
now Python fits the bill rather wonderfully.





More information about the Python-list mailing list