[Types-sig] const (was: PyDL RFC 0.02)
skaller
skaller@maxtal.com.au
Thu, 30 Dec 1999 12:36:29 +1100
Paul Prescod wrote:
> It is quite possible that at some point I used const inconsistently to
> mean both "non-rebindable name" and "immutable." Greg is right that I
> was thinking about the latter when I put it in. In the long run we
> really need both, but I will remove them from version 1 for now.
Hang on! removing 'const' is not the same as
adding a restriction preventing certain name rebindings --
as Guido pointed out in response to one of my posts,
it is possible to detect many rebindings, and it is possible
to ban some -- without needing a 'const' specification.
> For now, we just need a solid definition of what types of rebinding are
> legal. There are four kinds of names:
No. There is only one kind of name.
Perhaps you mean 'a name can be bound to one of four kinds of object'?
> * module -- we must always disallow rebinding these because we don't
> have a notion of two modules with the "same interface". Maybe in some
> future version we could.
I'm not so sure. Consider:
import m
module_x = m.x
module_x = m.y
Here, 'module_x' is a name bound to a module, namely m.x,
which is rebound to another module, m.y. Module objects
can be accessed just like any other python object.
And in this case, you may not even KNOW that 'module_x'
is bound to a module object.
I'm thinking that your intent is that the name 'module_x'
be declared as a module (with some properties), but then ..
> * class -- rebinding is fine as long as the new class has a signuture
> that will produce instances that conform to the declared interface(s).
.. should be the same as for modules. Rebinding
is allowed, provided the constraints implied by a declaration
the name conforms to a particular interface are met.
> * functions and other objects -- rebinding is fine as long as the new
> function conforms to the declared interface.
I think a better and simpler rule is to be found
by simply taking this rule without the words
'functions and other'
-- i.e. the rule applies uniformly to all objects.
[not sure though]
BUT: the is an important reason to do more,
namely, caching of module functions and class methods.
In this case, merely requiring interface conformance
is not enough: we'd actually want to prevent rebinding.
This can be done by banning:
x.f = g
where x is a module or class: it is still permitted
where x is an instance. (Other cases??)
--
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