[Python-ideas] Adding "Typed" collections/iterators to Python

Nick Coghlan ncoghlan at gmail.com
Wed Dec 21 02:14:52 CET 2011

On Wed, Dec 21, 2011 at 10:51 AM, Devin Jeanpierre
<jeanpierreda at gmail.com> wrote:
> Perhaps, instead, we should stop claiming things are "strong" or
> "weak". If I said that, relatively speaking, Python is weakly typed,
> people would get offended -- not because I made any technically
> incorrect statement (on the spectrum, Python is far closer to assembly
> than Agda), but because to call it "weak" is insulting.

When you can mutate a str object into an int object (or vice-versa),
then you can claim Python is weakly typed without being technically

Weak typing has a very specific meaning: objects can change their type
without changing their identity (e.g. via pointer casting in C and
C++). Python lets objects *lie* about their types to some degree (by
altering __class__), but type(obj) will always reveal the true
underling type (indeed, "obj.__class__ != type(obj)" is one of the
ways to detect when you've been given a proxy object, if the
distinction matters for a particular use case). (For CPython,
extension module authors can actually use C code to get around the
strong typing if they really try, but the authors of such code get no
sympathy when it inevitably blows up in obscure and hard to debug
ways. Old-style classes in 2.x can also be legitimately described as
weakly typed, since *all* instances of such classes share a single
underlying type, and __class__ is the true determinant of their

Weak vs strong typing and dynamic vs static typing are well-defined
concepts - it's just all too common that folks that initially learn to
program with a static language confuse the two spectra and think that
"static typing" and "strong typing" are the same thing. They're not
only not the same, they're actually completely orthogonal. CPython,
for example, uses the weak static typing of C to implement Python's
strong dynamic typing mechanisms. IronPython and Jython have strong
typing at both levels, but retain the static vs dynamic split. I
believe PyPy uses strong dynamic typing throughout (although RPython
has a type inference mechanism and a few other tricks to support
translation to machine code)


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list