nucleic / enaml

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

Inheritance behaviour is broken with atom 0.9.0 #519

Closed gabrielcnr closed 1 year ago

gabrielcnr commented 1 year ago

I updated atom in my environment today from 0.8.2 to 0.9.0 (latest) using the packages from conda-forge.

The behaviour for the inheritance of enaml defined types seem to have been broken on the latest version.

I tried to code a little example that reproduces the issue:

from enaml.widgets.api import *

enamldef UpperLabel(Label):
    attr lower_text
    text << lower_text.upper()

enamldef UpperLabel2(UpperLabel):
    attr some_text
    lower_text << some_text.strip()

enamldef Main(Window):
    Container:
        UpperLabel2:
            some_text << 'Hello World   '

Before this used to work fine and display a widget with the label HELLO WORLD.

It works in an environment with:

enaml 0.15.2
atom 0.8.2
python 3.10.9

However it the gives the following error if you bump atom==0.9.0:

Traceback (most recent call last):
  File "/Users/greis/dev/conda/envs/enaml-bug/bin/enaml-run", line 11, in <module>
    sys.exit(main())
  File "/Users/greis/dev/conda/envs/enaml-bug/lib/python3.10/site-packages/enaml/runner.py", line 61, in main
    exec(code, ns)
  File "enamlbug.enaml", line 1, in
    from enaml.widgets.api import *
  File "enamlbug.enaml", line 1, in UpperLabel2
    from enaml.widgets.api import *
  File "enamlbug.enaml", line 11, in UpperLabel2
    lower_text << some_text.strip()
TypeError: 'lower_text' is not a declarative member
MatthieuDartiailh commented 1 year ago

You need to update enaml to 0.16.0. Atom 0.9.0 fixed a nasty inheritance bug and to do so had to modify how a member can be added to a class after its definition. Enaml 0.16.0 uses the new way and should work as expected.