[Edu-sig] Terminology question: just operator overriding?

Kirby Urner urnerk@qwest.net
Fri, 27 Jun 2003 11:08:17 -0700


When I think of operators, I think of binary and unary operators
like * + / ** or ~ - but not of other syntax, like parentheses
or square brackets, as in p() and p[].

However in Python we're able to define new meanings for these
other kinds of syntax as well:

  >>> class Foo(object):
	def __getattribute__(self,attr):
	    return "Bar!"
	def __getitem__(self,it):
	    return "Blimey!"
	def __call__(self,var):
	    return "Hello?"

	
  >>> p = Foo()

  >>> p.spam
  'Bar!'
  >>> p(3)
  'Hello?'
  >>> p['3']
  'Blimey!'

So do we call it "operator overriding" in all these cases, or
do some people say "syntax overriding" or something else that
sounds more general than "operator".

Kirby

PS:  given the above class def, when I go
   >>> p(  # <--- just an opening paren
in IDLE, it prompts with "Bar!".  Not sure why.