Skip to content

DualMap.add_child returns None, so chained add_child calls fail #2392

Backlog

Description

@shashank11yadav

Describe the bug

DualMap.add_child does not return anything, so chaining calls like DualMap(...).add_child(a).add_child(b) raises AttributeError. Marker.add_child had the same problem and was fixed in #2145.

To Reproduce

import folium
from folium.plugins import DualMap

dm = DualMap(location=[0, 0])
dm.add_child(folium.Marker([0, 0])).add_child(folium.Marker([1, 1]))

Output:

AttributeError: 'NoneType' object has no attribute 'add_child'

I get the same error on release 1.0.0 and on main (2b2d105).

Expected behavior

add_child returns the object it was called on, so calls chain. Marker.add_child does this since #2145 (folium/map.py, return self).

Environment

  • Browser: not relevant
  • Jupyter Notebook or html files: plain Python script
  • Python version: 3.12 (Linux)
  • folium version: 1.0.0 and main @ 2b2d105
  • branca version: 0.8.2

Additional context

DualMap.add_child in folium/plugins/dual_map.py (lines 102-107) has no return self.

Possible solutions

Return self at the end of the method, with a test asserting dm.add_child(folium.Marker([0, 0])) is dm.

I have a fix with a regression test ready and will open a pull request for it right after filing this issue; it will link back here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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