Skip to content

Commit

Permalink
_clean_text -> clean_text (#2496)
Browse files Browse the repository at this point in the history
  • Loading branch information
tconkling committed Dec 21, 2020
1 parent a03d3b9 commit 63633ad
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
10 changes: 5 additions & 5 deletions lib/streamlit/elements/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import streamlit
from streamlit.proto.Alert_pb2 import Alert as AlertProto
from .utils import _clean_text
from .utils import clean_text


class AlertMixin:
Expand All @@ -34,7 +34,7 @@ def error(self, body):
"""
alert_proto = AlertProto()
alert_proto.body = _clean_text(body)
alert_proto.body = clean_text(body)
alert_proto.format = AlertProto.ERROR
return self.dg._enqueue("alert", alert_proto)

Expand All @@ -52,7 +52,7 @@ def warning(self, body):
"""
alert_proto = AlertProto()
alert_proto.body = _clean_text(body)
alert_proto.body = clean_text(body)
alert_proto.format = AlertProto.WARNING
return self.dg._enqueue("alert", alert_proto)

Expand All @@ -70,7 +70,7 @@ def info(self, body):
"""
alert_proto = AlertProto()
alert_proto.body = _clean_text(body)
alert_proto.body = clean_text(body)
alert_proto.format = AlertProto.INFO
return self.dg._enqueue("alert", alert_proto)

Expand All @@ -88,7 +88,7 @@ def success(self, body):
"""
alert_proto = AlertProto()
alert_proto.body = _clean_text(body)
alert_proto.body = clean_text(body)
alert_proto.format = AlertProto.SUCCESS
return self.dg._enqueue("alert", alert_proto)

Expand Down
14 changes: 7 additions & 7 deletions lib/streamlit/elements/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import streamlit
from streamlit import type_util
from streamlit.proto.Markdown_pb2 import Markdown as MarkdownProto
from .utils import _clean_text
from .utils import clean_text


class MarkdownMixin:
Expand Down Expand Up @@ -73,7 +73,7 @@ def markdown(self, body, unsafe_allow_html=False):
"""
markdown_proto = MarkdownProto()

markdown_proto.body = _clean_text(body)
markdown_proto.body = clean_text(body)
markdown_proto.allow_html = unsafe_allow_html

return self.dg._enqueue("markdown", markdown_proto)
Expand All @@ -96,7 +96,7 @@ def header(self, body):
"""
header_proto = MarkdownProto()
header_proto.body = "## %s" % _clean_text(body)
header_proto.body = "## %s" % clean_text(body)
return self.dg._enqueue("markdown", header_proto)

def subheader(self, body):
Expand All @@ -117,7 +117,7 @@ def subheader(self, body):
"""
subheader_proto = MarkdownProto()
subheader_proto.body = "### %s" % _clean_text(body)
subheader_proto.body = "### %s" % clean_text(body)
return self.dg._enqueue("markdown", subheader_proto)

def code(self, body, language="python"):
Expand Down Expand Up @@ -150,7 +150,7 @@ def code(self, body, language="python"):
"language": language or "",
"body": body,
}
code_proto.body = _clean_text(markdown)
code_proto.body = clean_text(markdown)
return self.dg._enqueue("markdown", code_proto)

def title(self, body):
Expand All @@ -174,7 +174,7 @@ def title(self, body):
"""
title_proto = MarkdownProto()
title_proto.body = "# %s" % _clean_text(body)
title_proto.body = "# %s" % clean_text(body)
return self.dg._enqueue("markdown", title_proto)

def latex(self, body):
Expand Down Expand Up @@ -212,7 +212,7 @@ def latex(self, body):
body = sympy.latex(body)

latex_proto = MarkdownProto()
latex_proto.body = "$$\n%s\n$$" % _clean_text(body)
latex_proto.body = "$$\n%s\n$$" % clean_text(body)
return self.dg._enqueue("markdown", latex_proto)

@property
Expand Down
4 changes: 2 additions & 2 deletions lib/streamlit/elements/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import streamlit
from streamlit.proto.Text_pb2 import Text as TextProto
from .utils import _clean_text
from .utils import clean_text


class TextMixin:
Expand All @@ -38,7 +38,7 @@ def text(self, body):
"""
text_proto = TextProto()
text_proto.body = _clean_text(body)
text_proto.body = clean_text(body)
return self.dg._enqueue("text", text_proto)

@property
Expand Down
3 changes: 2 additions & 1 deletion lib/streamlit/elements/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class NoValue(object):
pass


def _clean_text(text):
def clean_text(text: Any) -> str:
"""Convert an object to text, dedent it, and strip whitespace."""
return textwrap.dedent(str(text)).strip()


Expand Down

0 comments on commit 63633ad

Please sign in to comment.