-
Notifications
You must be signed in to change notification settings - Fork 17
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
Stubs for public interface #58
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||
import pathlib | ||||
import typing as t | ||||
|
||||
if t.TYPE_CHECKING: | ||||
import typing_extensions as te | ||||
from _typeshed import SupportsRead | ||||
|
||||
from mjml.core.api import Component | ||||
|
||||
class _Output(t.NamedTuple): | ||||
html: str | ||||
errors: t.Sequence[str] | ||||
|
||||
@te.overload | ||||
def __getitem__(self, _: t.Literal["html"]) -> str: ... | ||||
@te.overload | ||||
def __getitem__(self, _: t.Literal["errors"]) -> t.Sequence[str]: ... | ||||
@te.overload | ||||
def get(self, key: t.Literal["html"], /) -> t.Optional[str]: ... | ||||
@te.overload | ||||
def get(self, key: t.Literal["html"], default: str, /) -> str: ... | ||||
@te.overload | ||||
def get(self, key: t.Literal["errors"], /) -> t.Optional[t.Sequence[str]]: ... | ||||
@te.overload | ||||
def get(self, key: t.Literal["errors"], default: t.Sequence[str], /) -> t.Sequence[str]: ... | ||||
|
||||
FpOrJson = t.Union[t.Dict[str, t.Any], str, bytes, SupportsRead[str], SupportsRead[bytes]] | ||||
StrOrPath = t.Union[str, pathlib.PurePath] | ||||
xoudini marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
||||
def mjml_to_html( | ||||
xml_fp_or_json: "FpOrJson", | ||||
skeleton: t.Optional[str] = None, | ||||
template_dir: t.Optional["StrOrPath"] = None, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is one of the places where types are really helpful as I looked through the code and I am not sure if a Maybe you can check my finding? (I am probably overlooking something) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This should be fine, as long as I used this annotation initially because there's already some string usage (as far as I can tell), for instance here: mjml-python/mjml/scripts/mjml.py Line 32 in ed3187e
|
||||
custom_components: t.Optional[t.List[t.Type["Component"]]] = None, | ||||
) -> "_Output": ... |
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.
Probably bike-shedding but does
mjml_to_html()
works ifxml_fp_or_json
contains abytes
value?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.
The
BeatifulSoup
constructor has the following annotation (in the stubs):Purely based on that it should work, since
bytes
is left untouched bymjml_to_html
, but I also quickly tried it, with a minimal example, and it seems to work just fine: