Static Typing in Python

John Roth newsgroups at jhrothjr.com
Sat Mar 13 12:16:19 CET 2004


"Premshree Pillai" <premshree_python at yahoo.co.in> wrote in message
news:mailman.349.1079161675.19534.python-list at python.org...
> --- Jacek Generowicz <jacek.generowicz at cern.ch>
> wrote: > Jacek Generowicz <jacek.generowicz at cern.ch>
> writes:
> >
> > > Peter Maas <fpetermaas at netscape.net> writes:
> > >
> > > > Premshree Pillai schrieb:
> > > > > How do I force static typing in Python?
> > > >
> > > > You have to enforce it by code instead of
> > declaration, i.e. you
> > > > have to do runtime type checking.
> > >
> > > Just what do you understand "static typing" to
> > mean ?
> >
> > I ask because I am prepared to accept that you have
> > a different
> > working definition of "static typing" from mine, but
> > people who
> > actually want static typing typically want it
> > because they think it
> > gives them the following advantages:
> >
> > a) type errors caught at compile time,
> >
> > b) faster program exectution.
> >
> > The code you showed:
> >
> > > > class doesTypeChecking:
> > > >      def __init__(self):
> > > >          self.__dict__["aString"] = ""
> > > >          self.__dict__["aFloat"] = 0.0
> > > >
> > > >      def __setattr__(self, attr, value):
> > > >          if type(self.__dict__[attr]) !=
> > type(value):
> > > >              raise ValueError, "Type mismatch
> > for attribute %s\n" % attr
> >
> > will catch no type errors at compile time, and will
> > slow down
> > execution, so I suspect that Premshree will be
> > disapponinted with it.
> >
> >
> > (BTW, my definition of "static typing" is "type
> > checking is done at
> > compile time" ... your example really looks like
> > dynamic typing to
> > me ... albeit with some restrictions on attribute
> > types.)
> >
> >
> > Premshree: Python is dynamically typed. There is no
> > way to enforce
> >            static typing. There is something called
> > "pychecker" which
> >            might be of some help to you. Why do you
> > think that you
> >            want static typing in Python ?
> > -- 
> > http://mail.python.org/mailman/listinfo/python-list
>
> Yes, I am aware that Python is dynamically typed, and
> so is Perl, right? In Perl, we have the "use strict
> vars" pragma to force variable declaration. Is there
> something like it in Python?

No.

> Don't you think forced variable declaration is an
> important requirement in a language?

No.

John Roth
>
> =====
> -Premshree
> [http://www.qiksearch.com/]
>
> ________________________________________________________________________
> Yahoo! India Insurance Special: Be informed on the best policies,
services, tools and more.
> Go to: http://in.insurance.yahoo.com/licspecial/index.html
>





More information about the Python-list mailing list