[Types-sig] type declaration syntax

skaller skaller@maxtal.com.au
Fri, 24 Dec 1999 04:40:29 +1100


Guido van Rossum wrote:

> > 2) Specify that 'def' creates an immutable binding. You can't
> >    rebind (or del) the name. Same for 'class'. [This includes
> >     defs inside classes]

> Agreed.  I proposed most of this a week ago.  

	Yes, I guess I was trying to summarise more than propose
anything new.

> However, I don't see why
> you propose to disallow rebinding def and class.  I proposed to have
> a warning for this.  If they are rebound, it is easily detected, so
> the effects can simply be calculated by the type checker.

	You're at least right that my stance on 'const' variables
and classes/functions is inconsistent. The rebinding rule was also
intended
to conver nested classes and functions. At present:

	def f():
		class X: pass
		return X()

	x1 = X()
	x2 = X()
	assert classof(x1) != classof(x2)

I hoped to eliminate this excess dynamism. .. redefining
the class every function invocation is rarely desirable.

But it may be harder than I thought, because even though
CPython does not lexically scope function bodies 
(Viper does .. so my rule would break it),
default arguments _are_ lexically scoped.
And perhaps it is best left alone, since nested classes and
functions are rarely used. [I mean, nested in functions]

Hmm. I have already put a test in Viper for module.attr = value.
I found I used it in a couple of places, initialising the sys module.
[specifically, assigning the standard input/output files]
I like the warning.

I guess I could put duplicate defintion warnings in easily,
and see what warnings I get.

-- 
John Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
voice: 61-2-9660-0850