property problems
Alex Martelli
aleax at aleax.it
Fri Nov 15 09:19:11 EST 2002
Antonio Cuni wrote:
> Alex Martelli wrote:
>
>> What really determines if x is a new-style class is x's metaclass,
>> and rather than inheriting it from x's base (which is the normal
>> way to do it) you may alternatively choose to assert it explicitly
>> by a __metaclass__ attribute in class scope (or a global variable
>> __metaclass__ in module scope if x has no bases). x is new-style
>> iff x's metaclass is the built-in type object named 'type'.
>
> uhm... type inherit from object, but object's metaclass is type: isn't
> there a recursion problem?
>
> ciao Anto
> PS & OT: what's the english for "circolo vizioso"?
"Vicious circle" is fine.
There isn't one in the case you mention, though. Suppose you had
a bunch of thingies with two attributes each:
athingy.mybase the thingy that's athingy's base, or None
athingy.mytype the thingy that's athingy's type, or None
and in particular that object and type were names of two thingies, now:
object.mytype = type
type.mybase = object
where is the "recursion problem"? Thingies ARE allowed to point to
each other -- what problem do you see with this?
If you write CODE that tries to navigate this graph, you do of
course have to be aware that it's not necessarily an acyclic graph
(depending on what set of links you consider). So...? Your code
may indeed have "recursion problems" if it unwarrantedly assumes
it's navigating an acyclic graph where the assumption doesn't hold,
of course. But that would hardly be surprising -- whenever you write
code that assumes more conditions than can be guaranteed, problems
of one kind or another are likely to arise.
Alex
More information about the Python-list
mailing list