Skip to content

Conversation

@pixelsapphire
Copy link
Contributor

A DivIcon works when passed as the icon argument of Marker, but the argument is annotated as Optional[Icon] instead of Optional[Union[Icon, "DivIcon"]].

Copy link
Member

@Conengmo Conengmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pixelsapphire, thanks for your PR, that makes sense! Good to improve this.

It's missing an import of that class, can you maybe add that? It will lead to a circular import, so the way to address that is by only importing it for type checking:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from folium.features import DivIcon

One more thing: I assume this argument also accepts CustomIcon objects. Maybe you can add that as well?

Thanks for your help!

@pixelsapphire
Copy link
Contributor Author

It's missing an import of that class

My bad, should have checked that first.

I assume this argument also accepts CustomIcon objects. Maybe you can add that as well?

Done and dusted.

@hansthen
Copy link
Collaborator

@Conengmo Do you know what is the issue with the failing mypy checks? It seems mypy is bothered by some method signature redefinitions between Branca and Folium.

@pixelsapphire
Copy link
Contributor Author

pixelsapphire commented Dec 24, 2024

@hansthen This is something I've been wondering about too. Why does the render method in Folium classes return None, when this method in Branca classes (and in the Element class itself) returns str?

@Conengmo
Copy link
Member

Conengmo commented Dec 29, 2024

I'm trying to reproduce this issue locally...

When I upgrade my local packages I get the same issue. It also occurs on the main branch.

The change in this PR doesn't cause the issue, and also doesn't add any type issues (the number of issues on this PR and the main branch is the same).

I'll work on fixing the issues in a separate PR.

Means we can go ahead and merge this PR!

@Conengmo Conengmo changed the title Add DivIcon as accepted type of Marker icon Add DivIcon and CustomIcon as accepted type of Marker icon Dec 29, 2024
@Conengmo Conengmo merged commit 09c5905 into python-visualization:main Dec 29, 2024
10 of 11 checks passed
@Conengmo
Copy link
Member

Thanks @pixelsapphire! This PS is much appreciated, I hadn't noticed this!

@hansthen
Copy link
Collaborator

hansthen commented Dec 29, 2024

@hansthen This is something I've been wondering about too. Why does the render method in Folium classes return None, when this method in Branca classes (and in the Element class itself) returns str?

I have been banging my head on this for a few days now. The signature redefinition seems to start already in Branca. See brana.element.Figure for instance. The children are void rendered (without actually returning anything). Then the _template of Figure is rendered. This will render just the header, html and script attributes and return the result.

    def render(self, **kwargs):
        """Renders the HTML representation of the element."""
        for name, child in self._children.items():
            child.render(**kwargs)
        return self._template.render(this=self, kwargs=kwargs)

In branca.element.MacroElement, the children are also void rendered, but here the render method itself also has a void signature.

I will open a discussion on the talk page for this.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants