[Python-Dev] Object customization (was: Arbitrary attributes on funcs and methods)

Moshe Zadka Moshe Zadka <mzadka@geocities.com>
Sat, 15 Apr 2000 07:06:00 +0200 (IST)


On Fri, 14 Apr 2000, Vladimir Marangozov wrote:

> If you prefer embedded definitions, among other things, you could do:
> 
> 	__zope_access__ = { 'Spam' : 'public' }
> 
> 	class Spam:
> 	    __zope_access__ = { 'eggs' : 'private',
>                                 'eats' : 'public' }
> 	    def eggs(self, ...): ...
>             def eats(self, ...): ...

This solution is close to what the eff-bot suggested. In this case it
is horrible because of "editing effort": the meta-data and code of a
function are better off together physically, so you would change it
to

class Spam:
	__zope_access__ = {}
	def eggs(self):
		pass
	__zope_access__['eggs'] = 'private'
	def eats(self):
		pass
	__zope_access__['eats'] = 'public'

Which is way too verbose. Especially, if the method gets thrown around,
you find yourself doing things like 

meth.im_class.__zope_access__[meth.im_func.func_name]

Instead of

meth.__zope_access__

And sometimes you write a function:

def do_something(self):
	pass

And the infrastructure adds the method to a class of its choice. Where
would you stick the attribute then?


--
Moshe Zadka <mzadka@geocities.com>. 
http://www.oreilly.com/news/prescod_0300.html
http://www.linux.org.il -- we put the penguin in .com