nucleic / enaml

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

Member index messed up with latest atom & enaml? #534

Closed frmdstryr closed 9 months ago

frmdstryr commented 9 months ago

I just updated to atom/enaml (0.10.2, 0.16.1) and stared getting nonsensical errors.

Traced it to when an attribute overrides an existing attribute.

For example:

from enaml.core.api import Conditional, Looper
from enaml.widgets.api import Window, Container, Label

enamldef ErrorContainer(Container): container:
    attr errors: list = []
    Looper:
        iterable << container.errors
        Label:
            text = loop.item

enamldef CustomContainer(ErrorContainer):
    attr errors: list = [] # Works fine if this is commented out
    Label:
        text = "Bar"

enamldef Main(Window): window:
    CustomContainer:
        pass

WTF ???

$ enaml-run tests/example.enaml 
Traceback (most recent call last):
  File "/home/test/micormamba/envs/test/bin/enaml-run", line 8, in <module>
    sys.exit(main())
  File "/home/test/micormamba/envs/test/lib/python3.10/site-packages/enaml/runner.py", line 69, in main
    window.show()
  File "/home/test/micormamba/envs/test/lib/python3.10/site-packages/enaml/widgets/window.py", line 382, in show
    self.activate_proxy()
  File "/home/test/micormamba/envs/test/lib/python3.10/site-packages/enaml/widgets/toolkit_object.py", line 213, in activate_proxy
    child.activate_proxy()
  File "/home/test/micormamba/envs/test/lib/python3.10/site-packages/enaml/widgets/toolkit_object.py", line 214, in activate_proxy
    self.activate_bottom_up()
  File "/home/test/micormamba/envs/test/lib/python3.10/site-packages/enaml/widgets/toolkit_object.py", line 236, in activate_bottom_up
    self.proxy.activate_bottom_up()
  File "/home/test/micormamba/envs/test/lib/python3.10/site-packages/enaml/qt/qt_toolkit_object.py", line 80, in activate_bottom_up
    self.init_layout()
  File "/home/test/micormamba/envs/test/lib/python3.10/site-packages/enaml/qt/qt_container.py", line 337, in init_layout
    self._setup_manager()
  File "/home/test/micormamba/envs/test/lib/python3.10/site-packages/enaml/qt/qt_container.py", line 541, in _setup_manager
    manager.set_items(self._create_layout_items())
  File "/home/test/micormamba/envs/test/lib/python3.10/site-packages/enaml/layout/layout_manager.py", line 309, in set_items
    hc = root.hard_constraints()
  File "/home/test/micormamba/envs/test/lib/python3.10/site-packages/enaml/layout/layout_manager.py", line 55, in hard_constraints
    return [d.left >= 0, d.top >= 0, d.width >= 0, d.height >= 0]
TypeError: '>=' not supported between instances of 'list' and 'int'

It seems like the member index is messed up somehow.

MatthieuDartiailh commented 9 months ago

What Python version are you running ?

MatthieuDartiailh commented 9 months ago

That is reminiscent of an inheritance bug that was fixed in atom. I will investigate but may not have the cycles to do so before next Monday.

frmdstryr commented 9 months ago

Seen on 3.10.2, 3.10.12, 3.9.16

frmdstryr commented 9 months ago

I think this should be member.set_index(existing.index) ? member.set_index(member.index)