Static Typing in Python

Dang Griffith google0 at lazytwinacres.net
Tue Mar 16 17:34:53 EST 2004


On Tue, 16 Mar 2004 02:28:15 +0000 (GMT), Premshree Pillai
<premshree_python at yahoo.co.in> wrote:

> --- Joe Mason <joe at notcharles.ca> wrote: > In article
>>
><mailman.11.1079347355.12241.python-list at python.org>,
>> Premshree Pillai wrote:
>> > Err...you probably have the wrong idea of static
>> > typing, I think. Static typing has to do with
>> explicit
>> > declaration (initialization) of variables (and not
>> of
>> > variable types). Like in C, C++, etc, Python too
>> is
>> 
>> Is that an official definition from somewhere? 
>> Cause I always thought
>> static typing was about variable types.
>> 
>> Joe
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list
>
>Hmm...I might have been a little wrong there. However,
>what I wanted to stress was that it's the explicit
>declaration of the variable that matters (that makes
>static typing what it is).

Static typing does not have to do with explicit declaration.
As you said earlier, Perl has an option to force explicit
declaration, and yet Perl is not statically typed.  Python function
arguments are explicitly declared, but are dynamically typed.

It seems you want the compiler to complain when a
previously unused/unnamed/undeclared variable is 
used on the left side of an equation.  (It already complains
for vars on the right side and in expressions.)

I think there is value in detecting such problems, but I 
think there is enough evidence in existing Python code
that there is little value to having it *in the language 
itself*.  As other posters have pointed out, there are
other ways of detecting these problems, such as with
pychecker and PyRex.

I'm bowing out of this discussion.  I hope I have been
somewhat helpful.  The strong/weak/static/dynamic
discussion has gone on many times before, and I don't
see it as being particularly relevant to explicit declaration.


I'm pretty sure you have the answer to your question.
Python does not force, or even support, variable declaration.
If you want that, you'll need to look to one of the other
tools mentioned.

Best wishes in your endeavors,
    O-O
        --Daniel 'dang' Griffith
p.s.
(Yes, I know Python supports variable/keyword arguments 
to functions, which don't require explicit declaration...)



More information about the Python-list mailing list