A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-March/020656.html below:

[Python-Dev] Explorations on new-style classes

[Python-Dev] Explorations on new-style classesDavid Abrahams David Abrahams" <david.abrahams@rcn.com
Tue, 5 Mar 2002 17:22:14 -0500
----- Original Message -----
From: "Kevin Jacobs" <jacobs@penguin.theopalgroup.com>


> Second, I've been twisting metaclasses to do my evil bidding.

Fun, innit?

> In this case,
> I have implemented pseudo-typed attributes and slots in Python. e.g.:
>
>   class A(object):
>     __metaclass__ = ConstrainedObject
>     __slots__ = {'a':int,'b':float}

Although I understand the appeal, using __slots__ to constrain the
attributes might be misguided (depending on your goals):

    >>> class A(object):
    ...     __slots__ = [ 'a' ]
    ...
    >>> class B(object):
    ...     __slots__ = [ 'b' ]
    ...
    >>> class C(A,B): pass
    ...
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    TypeError: multiple bases have instance lay-out conflict
    >>> class D(object): pass
    ...
    >>> class C(A,D): pass
    ...
    >>>







RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4