You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow blocks to override Field defaults without copying the original field #169
Currently, to change the default value of a field (such as display_name), a block needs to copy the definition. This means that if other values in the field need to change, they need to be changed in many places, which is subpar.
When this happens, accidentally overriding a field should raise an exception.
Proposal:
class FooBlock(XBlock):
display_name = OverrideField(default='Foo Block') # Uses the same field definition as the parent, with kwargs overridden
tags = Field(...) # raises an exception, because it hides a parent field
name = OverrideField(scope=scope.user_state) # Error, can't override the scope
How often has a subclass wanted to keep a field but change its default? This seems like an odd operation to me. There must be some real examples we can look at, I know you didn't invent this for the fun of it.
Activity
cpennington commentedon Jan 24, 2014
When this happens, accidentally overriding a field should raise an exception.
Proposal:
cpennington commentedon Jan 24, 2014
@nedbat @jorr-at-google: Thoughts?
nedbat commentedon Jan 27, 2014
How often has a subclass wanted to keep a field but change its default? This seems like an odd operation to me. There must be some real examples we can look at, I know you didn't invent this for the fun of it.
cpennington commentedon Jan 27, 2014
We do it constantly for
display_name.