mjml-python icon indicating copy to clipboard operation
mjml-python copied to clipboard

Stubs for public interface

Open xoudini opened this issue 1 year ago • 3 comments

This is a minimal PR, which (mostly) resolves #50, as discussed in #57.

For overriding components in downstream projects, the public interface of all components should be typed accordingly, but I'll leave that for the next PR (unless it's seen as pertinent to do here while we're at it).

For instance, calls like this: https://github.com/FelixSchwarz/mjml-python/blob/ed3187e2d7f22ab39848f056e7406ef0b2118aff/tests/custom_components_test.py#L28-L31

...will cause mypy to error with:

error: Call to untyped function "render" in typed context  [no-untyped-call]

The same goes for e.g. default_attrs and so on, so type annotations should be added to these as soon as possible.

xoudini avatar Jul 10 '24 22:07 xoudini

See mypy docs on stubs for more details.

The stubs can be deleted later, when the package is typed internally.

xoudini avatar Jul 10 '24 22:07 xoudini

Also added type hints for the dictionary interface of the output (since dotmap.DotMap is also a dictionary). These can be removed if attribute access on the result should be enforced (or if treating the result as a dictionary should be discouraged).

xoudini avatar Jul 11 '24 11:07 xoudini

Sorry for the long delay. I just added a few minor comments but other than that it looks good to merge.

No worries at all!

Speaking of bike-shedding, there's currently an annotation for custom_components expecting an optional list:

https://github.com/FelixSchwarz/mjml-python/blob/ed3187e2d7f22ab39848f056e7406ef0b2118aff/mjml/mjml2html.py#L22-L23

Since this list isn't actually mutated, it would be sufficient to annotate it as a typing.Sequence (or collections.abc.Sequence once Python 3.9 is used as the baseline). Should I update these while I'm at it, or leave it for later?

xoudini avatar Aug 14 '24 20:08 xoudini

Sorry for letting this slip for so long. I cherry-picked your commits and pushed them in main. Release will follow later today.

FelixSchwarz avatar May 13 '25 09:05 FelixSchwarz