Skip to content

Commit

Permalink
Add fallback_to_none to docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
alugowski committed Sep 8, 2023
1 parent 7e2c728 commit 6de731d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions matrepr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,14 @@ def _get_adapter(mat: Any, options: Optional[MatReprParams], unsupported_raise=T
return adapter


def to_html(mat: Any, notebook=False, fallback_to_None=False, **kwargs) -> str:
def to_html(mat: Any, notebook=False, fallback_to_none=False, **kwargs):
"""
Render a matrix to HTML.
:param mat: A supported matrix.
:param notebook: If true then adds extra styling appropriate for display in a Jupyter notebook.
:param fallback_to_none: Whether to return None or a fallback LaTeX string
if the formatter asks to fall back to native formatting.
:param kwargs: Any argument in :class:`MatReprParams`.
:rtype: str
:return: A string containing an HTML representation of `mat`.
Expand All @@ -256,17 +258,19 @@ def to_html(mat: Any, notebook=False, fallback_to_None=False, **kwargs) -> str:
except FallbackToNative:
if hasattr(mat, "_repr_html_"):
return getattr(mat, "_repr_html_")()
elif fallback_to_None:
elif fallback_to_none:
return None
else:
return f"<pre>{str(mat)}</pre>"


def to_latex(mat: Any, fallback_to_None=False, **kwargs):
def to_latex(mat: Any, fallback_to_none=False, **kwargs):
"""
Render a matrix to LaTeX.
:param mat: A supported matrix.
:param fallback_to_none: Whether to return None or a fallback LaTeX string
if the formatter asks to fall back to native formatting.
:param kwargs: Any argument in :class:`MatReprParams`.
:rtype: str
:return: A string containing a LaTeX representation of `mat`.
Expand All @@ -280,7 +284,7 @@ def to_latex(mat: Any, fallback_to_None=False, **kwargs):
except FallbackToNative:
if hasattr(mat, "_repr_latex_"):
return getattr(mat, "_repr_latex_")()
elif fallback_to_None:
elif fallback_to_none:
return None
else:
return r"\texttt{" + tex_escape(str(mat)) + r"}"
Expand Down
2 changes: 1 addition & 1 deletion matrepr/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def _repr_html_(mat):
from . import to_html
return to_html(mat, notebook=True, fallback_to_None=True)
return to_html(mat, notebook=True, fallback_to_none=True)


def load_ipython_extension(ipython):
Expand Down
2 changes: 1 addition & 1 deletion matrepr/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def _repr_latex_(mat):
return to_latex(mat, fallback_to_None=True)
return to_latex(mat, fallback_to_none=True)


def load_ipython_extension(ipython):
Expand Down

0 comments on commit 6de731d

Please sign in to comment.