-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix type hints after adding Branca type checking #2060
Fix type hints after adding Branca type checking #2060
Conversation
@hansthen could you maybe take a look? This fixes the Mypy issues. If we get this merged, I'll make another patch release, since typing in Folium is broken in the latest release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some suggested changes but I am also fine to do this as is for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to rename these methods, since they really do something different than branca.Element.render
. See the discussion I started on the signature redefinition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand all the typing issues fully, but in general it looks good. I don't mind going ahead with this as is to fix the immediate issues. We can discuss my proposal to rename render
from MacroElement and its children at a later moment. Whatever you think is best for now.
Thanks for the review! You're right about |
In the recent Branca release we enabled type checking. This leads to issues when type checking Folium, since it relies on Branca. This PR addresses these issues.
Each commit in this PR contains a single fix, so you can walk through the commits to see what changes.
Render function
Note about the
render
function: I removed the return type, which effectively disables type checking. This is unfortunately necessary. In Branca we specify this function should return a string, but that's not what's done inMacroElement
and so basically everything in Folium. We should update the type in Branca, do a release, then add the types back in Folium. This is a lot of trouble so maybe not worth the effort.Bounds
The return type of bounds functions should allow for None values to be consistent. Even if we're sure a function returns floats not None, we still need to type it as optional. That's because the values are returned in a list, which is mutable.
Another thing is that some functions accept a
bounds
argument, which can be a list or tuple, but must have non-None values. Those types are distinct from bounds as return values, which should be list of list of optional float. Split the two in distinct types.VegaLite
In practice, a
VegaLite
only works if it's added to aFigure
,Div
orPopup
. We only have examples of that in our documentation, but it's not explicitly listed. Update the code to raise a meaningful error when this element is added to the wrong parent. This also then satisfies Mypy.