nucleic / enaml

Declarative User Interfaces for Python
http://enaml.readthedocs.io/en/latest/
Other
1.53k stars 130 forks source link

Make attr "final" by default and add a way to explicitly override #407

Closed frmdstryr closed 4 years ago

frmdstryr commented 4 years ago

I shot myself in the foot with this too often... can attr be changed to always be final so overriding it is an error unless it's somehow explicitly marked as overriding?

I don't want this

enamldef MyWindow(Window):
    attr a = 2

enamldef MyCustomWindow(MyWindow):
    attr a = 2 # This should blow up

But maybe this

enamldef MyWindow(Window):
    attr a = 2

enamldef MyCustomWindow(MyWindow):
    override attr a = 2 # This is ok because it let's someone know this is explicitly being overridden
MatthieuDartiailh commented 4 years ago

I would argue that this is general true in Python. You can do whatever you want in a subclass, I am not sure that enaml should be deviate from that.

frmdstryr commented 4 years ago

Maybe an alternative to making it final would be to emit some warnings to a logger when it's overridden? I'm not sure how frequently this is actually done purposefully.

Another thought I had was having the ability to pass "compiler options" for things like this to enaml.imports()? Eg like a strict mode or something which didn't allow overriding stuff.