Skip to content

Error when running Hotelling's Law example #2824

@venzen

Description

@venzen

Describe the bug
In Hotelling Law example, running app.py gives the following error:

ERROR:    Component react.component(__main__.SpaceDrawer) raised exception TypeError("'NoneType' object is not subscriptable")
Traceback (most recent call last):
  File "/data/mesa/venv/lib/python3.12/site-packages/reacton/core.py", line 1702, in _render
    root_element = el.component.f(*el.args, **el.kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/mesa/mesa-examples/examples/hotelling_law/app.py", line 141, in SpaceDrawer
    rect_x = pos[0] + (i * width)
             ~~~^^^
TypeError: 'NoneType' object is not subscriptable

Expected behavior
According to the PNG file included with the example, agents should be positioned on a grid.

To Reproduce

$ cd mesa-examples/examples/hotelling_law/
$ git branch
* main
$ solara run app.py

Additional context

$ python --version
Python 3.12.11
$ python -c "import mesa; print(mesa.__version__)"
3.2.0
$ uname -a
Linux --- 5.15.0-139-generic #149-Ubuntu SMP Fri Apr 11 22:06:13 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions