Copy constructors
Roman Suzi
rnd at onego.ru
Mon Aug 13 03:45:38 EDT 2001
On Mon, 13 Aug 2001, Roman Suzi wrote:
> For example, by using __builtin__ trick:
>
> class MyNumber(integer):
>
> def myadd(self, x, y):
> return x*y
>
> __builtin__.add = myadd
>
>
> The essence of the idea is to gather builtin (C) methods into special
> namespace: __builtin__, the same way it is done with builtin fuctions.
> This will allow Python programmers to remember less details and
> will give shadowing for free!!!
>
> The summary of proposal is to leave things as they are, but to introduce
> __builtin__ namespace for optimized methods.
>
> (Name __builtin__ could be different)
I forgot to mention that inheritance rules for __builtin__ could
be made explicit, if needed:
class MyNumber(no_builtins(type(1))):
...
or
class MyNumber(type(1)):
...
where no_builtins() is function on classes, making changes
to, say, __builtin__.
Or even:
class MyNumber(inline(type(1))):
...
Which will bring type(1).__builtin__ directly into
MyNumber namespace, wrapping raw C-methods if necessary.
I think, this is good idea.
And also I think class definitions must allow
to use sequences, so, some filter function could be applied:
class C(filter(myrule, [A,B])):
pass
Sincerely yours, Roman A.Suzi
--
- Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -
More information about the Python-list
mailing list