Replaceable Property question
I've stuck this in the Proposals Wiki as well so feel free to comment here or there :-) Will there be any access to the method/object that is being overridden from inside the one overriding it? Something like: 'self.__class__.my_method("blah")' ...but also accessible from DTML? Also, will folders have replaceableness for their contents? (so you could, for example, have a root index_html which could not be over-ridden lower down? cheers, Chris
Chris Withers wrote:
Will there be any access to the method/object that is being overridden from inside the one overriding it? Something like:
'self.__class__.my_method("blah")'
Depends on whether the original method comes from a ZClass or product. If so, yes. But if it's a regular object that's marked as replaceable and it's replaced, the original will vanish.
...but also accessible from DTML?
No. DTML will never have access to the replaced method.
Also, will folders have replaceableness for their contents? (so you could, for example, have a root index_html which could not be over-ridden lower down?
I don't understand your first question, but the answer to the second is "yes" regardless. :-) You would set index_html.__replaceable__ = ObjectManager.UNIQUE . Shane
Shane Hathaway wrote:
Will there be any access to the method/object that is being overridden from inside the one overriding it? Something like:
'self.__class__.my_method("blah")'
Depends on whether the original method comes from a ZClass or product. If so, yes. But if it's a regular object that's marked as replaceable and it's replaced, the original will vanish.
Will it re-appear when the replacement is deleted? That could be confusing...
...but also accessible from DTML?
No. DTML will never have access to the replaced method.
Oh well... could have been handy...
I don't understand your first question, but the answer to the second is "yes" regardless. :-) You would set index_html.__replaceable__ = ObjectManager.UNIQUE .
Cool, that's what I was looking for... cheers, Chris
Chris Withers wrote:
Shane Hathaway wrote:
Will there be any access to the method/object that is being overridden from inside the one overriding it? Something like:
'self.__class__.my_method("blah")'
Depends on whether the original method comes from a ZClass or product. If so, yes. But if it's a regular object that's marked as replaceable and it's replaced, the original will vanish.
Will it re-appear when the replacement is deleted?
That could be confusing...
No, and I think it's really not confusing, since it's quite a strange and rare thing to set __replaceable__=ObjectManager.REPLACEABLE on a normal instance. :-/ Think of it more like Python instances vs. classes. Setting __replaceable__=REPLACEABLE on a ZClass method is like setting a class attribute in Python, then overriding it in an instance is like setting an instance attribute. If you set __replaceable__=REPLACEABLE on an instance attribute, then replace it, it's like setting "foo.a = bar" then "foo.a = boo". The reference to "bar" disappears without any implicit recovery. Shane
Shane Hathaway wrote:
Will it re-appear when the replacement is deleted?
That could be confusing...
No, and I think it's really not confusing, since it's quite a strange and rare thing to set __replaceable__=ObjectManager.REPLACEABLE on a normal instance. :-/
Very true :-)
Think of it more like Python instances vs. classes. Setting __replaceable__=REPLACEABLE on a ZClass method is like setting a class attribute in Python, then overriding it in an instance is like setting an instance attribute. If you set __replaceable__=REPLACEABLE on an instance attribute, then replace it, it's like setting "foo.a = bar" then "foo.a = boo". The reference to "bar" disappears without any implicit recovery.
Hurm, that is a shame... What happens if you override a method (say Squishdot.render) and then delete your overriding method? Does it depend on whether you're talking about python products or ZClasses? cheers, Chris
Chris Withers wrote:
What happens if you override a method (say Squishdot.render) and then delete your overriding method?
In that case the method will revert to that provided by the class.
Does it depend on whether you're talking about python products or ZClasses?
Nope. They will behave the same way. Shane
Shane Hathaway wrote:
What happens if you override a method (say Squishdot.render) and then delete your overriding method?
In that case the method will revert to that provided by the class.
Does it depend on whether you're talking about python products or ZClasses?
Nope. They will behave the same way.
Great, that's what I was hoping :-) I understand your example better now too.. So, how long before this becomes a project and gets finished? 2.2.1 would be great :-)) thanke for the great work, Chris
participants (2)
-
Chris Withers -
Shane Hathaway