Extending Python: exception handling

Greg Ewing greg.ewing at compaq.com
Fri Aug 27 06:31:00 CEST 1999


John Skaller wrote:
> 
> The types of objects are NOT defined by Viper.
> They're defined in Python by a client module!
> So you can, for example, define any methods you like
> for any type. Here is the current definition of
> the type of an integer in the module 'py_types':
> 
>         class PyIntType:
>                 def succ(x): return x + 1
>                 def pred(x): return x - 1

That sounds very interesting! I've been pondering
the problem of type/class unification in Python,
and your solution is an intriguing one. But is
it possible to do this:

  class MyInteger(PyIntType):
    ... customised behaviour ...

and have it inherit all the default behaviour
of built-in integers? If so, how exactly does it
work? For instance, can I do

  x = MyInteger(3)
  y = x + 5

and, assuming I haven't given MyInteger a custom
__add__ method, have it somehow invoke the built-in
integer addition code.

Greg




More information about the Python-list mailing list