From 5c8d2387f1fb119e40250205008b3a18f891536f Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 11:58:53 +0200 Subject: [PATCH 01/16] Add some type annotations to __init__.py --- lib/streamlit/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/streamlit/__init__.py b/lib/streamlit/__init__.py index 0b9969f239cc..7eaa62b60149 100644 --- a/lib/streamlit/__init__.py +++ b/lib/streamlit/__init__.py @@ -206,7 +206,7 @@ def _update_logger(): beta_columns = _main.beta_columns -def set_option(key, value): +def set_option(key: str, value) -> None: """Set config option. Currently, only the following config options can be set within the script itself: @@ -372,7 +372,7 @@ def experimental_set_query_params(**query_params): @_contextlib.contextmanager -def spinner(text="In progress..."): +def spinner(text: str = "In progress..."): """Temporarily displays a message while executing a block of code. Parameters @@ -446,7 +446,7 @@ def _transparent_write(*args): _use_warning_has_been_displayed = False -def _maybe_print_use_warning(): +def _maybe_print_use_warning() -> None: """Print a warning if Streamlit is imported but not being run with `streamlit run`. The warning is printed only once. """ @@ -492,7 +492,7 @@ def stop() -> NoReturn: raise StopException() -def experimental_rerun(): +def experimental_rerun() -> NoReturn: """Rerun the script immediately. When `st.experimental_rerun()` is called, the script is halted - no From a53a5d04901185eb678b50e4d4dfb44c057b54d7 Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 13:01:06 +0200 Subject: [PATCH 02/16] Add type annotations to markdown.py --- lib/streamlit/elements/markdown.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/streamlit/elements/markdown.py b/lib/streamlit/elements/markdown.py index 047a79b64680..00a57b314b23 100644 --- a/lib/streamlit/elements/markdown.py +++ b/lib/streamlit/elements/markdown.py @@ -13,15 +13,21 @@ # limitations under the License. from typing import cast +from typing import TYPE_CHECKING import streamlit from streamlit import type_util from streamlit.proto.Markdown_pb2 import Markdown as MarkdownProto from .utils import clean_text +if TYPE_CHECKING: + import sympy + + from streamlit.delta_generator import DeltaGenerator + class MarkdownMixin: - def markdown(self, body, unsafe_allow_html=False): + def markdown(self, body: str, unsafe_allow_html: bool = False) -> DeltaGenerator: """Display string formatted as Markdown. Parameters @@ -74,7 +80,7 @@ def markdown(self, body, unsafe_allow_html=False): return self.dg._enqueue("markdown", markdown_proto) - def header(self, body, anchor=None): + def header(self, body: str, anchor: Optional[str] = None) -> DeltaGenerator: """Display text in header formatting. Parameters @@ -99,7 +105,7 @@ def header(self, body, anchor=None): header_proto.allow_html = True return self.dg._enqueue("markdown", header_proto) - def subheader(self, body, anchor=None): + def subheader(self, body: str, anchor: Optional[str] = None) -> DeltaGenerator: """Display text in subheader formatting. Parameters @@ -125,7 +131,7 @@ def subheader(self, body, anchor=None): return self.dg._enqueue("markdown", subheader_proto) - def code(self, body, language="python"): + def code(self, body: str, language: str = "python") -> DeltaGenerator: """Display a code block with optional syntax highlighting. (This is a convenience wrapper around `st.markdown()`) @@ -154,7 +160,7 @@ def code(self, body, language="python"): code_proto.body = clean_text(markdown) return self.dg._enqueue("markdown", code_proto) - def title(self, body, anchor=None): + def title(self, body: str, anchor: Optional[str] = None) -> DeltaGenerator: """Display text in title formatting. Each document should have a single `st.title()`, although this is not @@ -182,7 +188,7 @@ def title(self, body, anchor=None): title_proto.allow_html = True return self.dg._enqueue("markdown", title_proto) - def caption(self, body, unsafe_allow_html=False): + def caption(self, body: str, unsafe_allow_html: bool = False) -> DeltaGenerator: """Display text in small font. This should be used for captions, asides, footnotes, sidenotes, and @@ -225,7 +231,7 @@ def caption(self, body, unsafe_allow_html=False): caption_proto.is_caption = True return self.dg._enqueue("markdown", caption_proto) - def latex(self, body): + def latex(self, body: Union[str, sympy.Expr]) -> DeltaGenerator: # This docstring needs to be "raw" because of the backslashes in the # example below. r"""Display mathematical expressions formatted as LaTeX. @@ -260,6 +266,6 @@ def latex(self, body): return self.dg._enqueue("markdown", latex_proto) @property - def dg(self) -> "streamlit.delta_generator.DeltaGenerator": + def dg(self) -> DeltaGenerator: """Get our DeltaGenerator.""" return cast("streamlit.delta_generator.DeltaGenerator", self) From 4b5f22de844d9fa9c77376977fc26eb455fa0963 Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 13:05:08 +0200 Subject: [PATCH 03/16] Add type annotations to text.py --- lib/streamlit/elements/text.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/streamlit/elements/text.py b/lib/streamlit/elements/text.py index 47fc684f27bc..1b59ad20f679 100644 --- a/lib/streamlit/elements/text.py +++ b/lib/streamlit/elements/text.py @@ -13,14 +13,18 @@ # limitations under the License. from typing import cast +from typing import TYPE_CHECKING import streamlit from streamlit.proto.Text_pb2 import Text as TextProto from .utils import clean_text +if TYPE_CHECKING: + from streamlit.delta_generator import DeltaGenerator + class TextMixin: - def text(self, body): + def text(self, body: str) -> DeltaGenerator: """Write fixed-width and preformatted text. Parameters @@ -38,6 +42,6 @@ def text(self, body): return self.dg._enqueue("text", text_proto) @property - def dg(self) -> "streamlit.delta_generator.DeltaGenerator": + def dg(self) -> DeltaGenerator: """Get our DeltaGenerator.""" - return cast("streamlit.delta_generator.DeltaGenerator", self) + return cast(DeltaGenerator, self) From 802086ff86be0b0361cfb0ed2e5fb67cc07a19e1 Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 13:33:55 +0200 Subject: [PATCH 04/16] Update markdown.py Import Optional and avoid using DeltaGenerator directly in cast. --- lib/streamlit/elements/markdown.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/streamlit/elements/markdown.py b/lib/streamlit/elements/markdown.py index 00a57b314b23..264e7b8eacdd 100644 --- a/lib/streamlit/elements/markdown.py +++ b/lib/streamlit/elements/markdown.py @@ -13,6 +13,7 @@ # limitations under the License. from typing import cast +from typing import Optional from typing import TYPE_CHECKING import streamlit @@ -131,7 +132,7 @@ def subheader(self, body: str, anchor: Optional[str] = None) -> DeltaGenerator: return self.dg._enqueue("markdown", subheader_proto) - def code(self, body: str, language: str = "python") -> DeltaGenerator: + def code(self, body: str, language: Optional[str] = "python") -> DeltaGenerator: """Display a code block with optional syntax highlighting. (This is a convenience wrapper around `st.markdown()`) @@ -268,4 +269,4 @@ def latex(self, body: Union[str, sympy.Expr]) -> DeltaGenerator: @property def dg(self) -> DeltaGenerator: """Get our DeltaGenerator.""" - return cast("streamlit.delta_generator.DeltaGenerator", self) + return cast("DeltaGenerator", self) From 12f6a83edabeaae5a6ec5bc6dd8c8d3bac0139d9 Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 13:56:19 +0200 Subject: [PATCH 05/16] Fix issues in markdown.py --- lib/streamlit/elements/markdown.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/streamlit/elements/markdown.py b/lib/streamlit/elements/markdown.py index 264e7b8eacdd..12c97933c178 100644 --- a/lib/streamlit/elements/markdown.py +++ b/lib/streamlit/elements/markdown.py @@ -15,6 +15,7 @@ from typing import cast from typing import Optional from typing import TYPE_CHECKING +from typing import Union import streamlit from streamlit import type_util @@ -28,7 +29,7 @@ class MarkdownMixin: - def markdown(self, body: str, unsafe_allow_html: bool = False) -> DeltaGenerator: + def markdown(self, body: str, unsafe_allow_html: bool = False) -> "DeltaGenerator": """Display string formatted as Markdown. Parameters @@ -81,7 +82,7 @@ def markdown(self, body: str, unsafe_allow_html: bool = False) -> DeltaGenerator return self.dg._enqueue("markdown", markdown_proto) - def header(self, body: str, anchor: Optional[str] = None) -> DeltaGenerator: + def header(self, body: str, anchor: Optional[str] = None) -> "DeltaGenerator": """Display text in header formatting. Parameters @@ -106,7 +107,7 @@ def header(self, body: str, anchor: Optional[str] = None) -> DeltaGenerator: header_proto.allow_html = True return self.dg._enqueue("markdown", header_proto) - def subheader(self, body: str, anchor: Optional[str] = None) -> DeltaGenerator: + def subheader(self, body: str, anchor: Optional[str] = None) -> "DeltaGenerator": """Display text in subheader formatting. Parameters @@ -132,7 +133,7 @@ def subheader(self, body: str, anchor: Optional[str] = None) -> DeltaGenerator: return self.dg._enqueue("markdown", subheader_proto) - def code(self, body: str, language: Optional[str] = "python") -> DeltaGenerator: + def code(self, body: str, language: Optional[str] = "python") -> "DeltaGenerator": """Display a code block with optional syntax highlighting. (This is a convenience wrapper around `st.markdown()`) @@ -161,7 +162,7 @@ def code(self, body: str, language: Optional[str] = "python") -> DeltaGenerator: code_proto.body = clean_text(markdown) return self.dg._enqueue("markdown", code_proto) - def title(self, body: str, anchor: Optional[str] = None) -> DeltaGenerator: + def title(self, body: str, anchor: Optional[str] = None) -> "DeltaGenerator": """Display text in title formatting. Each document should have a single `st.title()`, although this is not @@ -189,7 +190,7 @@ def title(self, body: str, anchor: Optional[str] = None) -> DeltaGenerator: title_proto.allow_html = True return self.dg._enqueue("markdown", title_proto) - def caption(self, body: str, unsafe_allow_html: bool = False) -> DeltaGenerator: + def caption(self, body: str, unsafe_allow_html: bool = False) -> "DeltaGenerator": """Display text in small font. This should be used for captions, asides, footnotes, sidenotes, and @@ -232,7 +233,7 @@ def caption(self, body: str, unsafe_allow_html: bool = False) -> DeltaGenerator: caption_proto.is_caption = True return self.dg._enqueue("markdown", caption_proto) - def latex(self, body: Union[str, sympy.Expr]) -> DeltaGenerator: + def latex(self, body: Union[str, sympy.Expr]) -> "DeltaGenerator": # This docstring needs to be "raw" because of the backslashes in the # example below. r"""Display mathematical expressions formatted as LaTeX. @@ -267,6 +268,6 @@ def latex(self, body: Union[str, sympy.Expr]) -> DeltaGenerator: return self.dg._enqueue("markdown", latex_proto) @property - def dg(self) -> DeltaGenerator: + def dg(self) -> "DeltaGenerator": """Get our DeltaGenerator.""" return cast("DeltaGenerator", self) From 93e30ebc2c3ef533cdf41ca14d2da856f7b96ee7 Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 13:59:38 +0200 Subject: [PATCH 06/16] Fix issues in text.py --- lib/streamlit/elements/text.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/streamlit/elements/text.py b/lib/streamlit/elements/text.py index 1b59ad20f679..d687cf0f4f7d 100644 --- a/lib/streamlit/elements/text.py +++ b/lib/streamlit/elements/text.py @@ -24,7 +24,7 @@ class TextMixin: - def text(self, body: str) -> DeltaGenerator: + def text(self, body: str) -> "DeltaGenerator": """Write fixed-width and preformatted text. Parameters @@ -42,6 +42,6 @@ def text(self, body: str) -> DeltaGenerator: return self.dg._enqueue("text", text_proto) @property - def dg(self) -> DeltaGenerator: + def dg(self) -> "DeltaGenerator": """Get our DeltaGenerator.""" return cast(DeltaGenerator, self) From e0ac21fb119d052649be7ca5576847a28a22f561 Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 14:02:52 +0200 Subject: [PATCH 07/16] Formatting --- lib/streamlit/elements/markdown.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/streamlit/elements/markdown.py b/lib/streamlit/elements/markdown.py index 12c97933c178..bf0afdeda55b 100644 --- a/lib/streamlit/elements/markdown.py +++ b/lib/streamlit/elements/markdown.py @@ -24,7 +24,7 @@ if TYPE_CHECKING: import sympy - + from streamlit.delta_generator import DeltaGenerator From 79a4d099877d1064587736b2e8bc23067e7d9969 Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 14:14:30 +0200 Subject: [PATCH 08/16] Yet another missing forward ref --- lib/streamlit/elements/markdown.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/streamlit/elements/markdown.py b/lib/streamlit/elements/markdown.py index bf0afdeda55b..5492ad740503 100644 --- a/lib/streamlit/elements/markdown.py +++ b/lib/streamlit/elements/markdown.py @@ -17,7 +17,6 @@ from typing import TYPE_CHECKING from typing import Union -import streamlit from streamlit import type_util from streamlit.proto.Markdown_pb2 import Markdown as MarkdownProto from .utils import clean_text @@ -233,7 +232,7 @@ def caption(self, body: str, unsafe_allow_html: bool = False) -> "DeltaGenerator caption_proto.is_caption = True return self.dg._enqueue("markdown", caption_proto) - def latex(self, body: Union[str, sympy.Expr]) -> "DeltaGenerator": + def latex(self, body: Union[str, "sympy.Expr"]) -> "DeltaGenerator": # This docstring needs to be "raw" because of the backslashes in the # example below. r"""Display mathematical expressions formatted as LaTeX. From ebf46e71c78d2a098bc8b30099e21e56faedf9fc Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 14:26:34 +0200 Subject: [PATCH 09/16] Cast Any to DeltaGenerator --- lib/streamlit/elements/alert.py | 29 ++++++++++++++++++----------- lib/streamlit/elements/button.py | 4 ++-- lib/streamlit/elements/markdown.py | 21 ++++++++++++++------- lib/streamlit/elements/text.py | 5 +++-- 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/lib/streamlit/elements/alert.py b/lib/streamlit/elements/alert.py index a04b11ff693e..306fab6762cd 100644 --- a/lib/streamlit/elements/alert.py +++ b/lib/streamlit/elements/alert.py @@ -13,14 +13,17 @@ # limitations under the License. from typing import cast +from typing import TYPE_CHECKING -import streamlit from streamlit.proto.Alert_pb2 import Alert as AlertProto from .utils import clean_text +if TYPE_CHECKING: + from streamlit.delta_generator import DeltaGenerator + class AlertMixin: - def error(self, body): + def error(self, body: str) -> "DeltaGenerator": """Display error message. Parameters @@ -36,9 +39,10 @@ def error(self, body): alert_proto = AlertProto() alert_proto.body = clean_text(body) alert_proto.format = AlertProto.ERROR - return self.dg._enqueue("alert", alert_proto) + dg = self.dg._enqueue("alert", alert_proto) + return cast("DeltaGenerator", dg) - def warning(self, body): + def warning(self, body: str) -> "DeltaGenerator": """Display warning message. Parameters @@ -54,9 +58,10 @@ def warning(self, body): alert_proto = AlertProto() alert_proto.body = clean_text(body) alert_proto.format = AlertProto.WARNING - return self.dg._enqueue("alert", alert_proto) + dg = self.dg._enqueue("alert", alert_proto) + return cast("DeltaGenerator", dg) - def info(self, body): + def info(self, body: str) -> "DeltaGenerator": """Display an informational message. Parameters @@ -72,9 +77,10 @@ def info(self, body): alert_proto = AlertProto() alert_proto.body = clean_text(body) alert_proto.format = AlertProto.INFO - return self.dg._enqueue("alert", alert_proto) + dg = self.dg._enqueue("alert", alert_proto) + return cast("DeltaGenerator", dg) - def success(self, body): + def success(self, body: str) -> "DeltaGenerator": """Display a success message. Parameters @@ -90,9 +96,10 @@ def success(self, body): alert_proto = AlertProto() alert_proto.body = clean_text(body) alert_proto.format = AlertProto.SUCCESS - return self.dg._enqueue("alert", alert_proto) + dg = self.dg._enqueue("alert", alert_proto) + return cast("DeltaGenerator", dg) @property - def dg(self) -> "streamlit.delta_generator.DeltaGenerator": + def dg(self) -> "DeltaGenerator": """Get our DeltaGenerator.""" - return cast("streamlit.delta_generator.DeltaGenerator", self) + return cast("DeltaGenerator", self) diff --git a/lib/streamlit/elements/button.py b/lib/streamlit/elements/button.py index 14e23acb4617..28652b9b88a4 100644 --- a/lib/streamlit/elements/button.py +++ b/lib/streamlit/elements/button.py @@ -16,7 +16,7 @@ from streamlit.scriptrunner import ScriptRunContext, get_script_run_ctx from streamlit.type_util import Key, to_key -from typing import cast, Optional, Union, BinaryIO, TextIO +from typing import cast, Final, Optional, Union, BinaryIO, TextIO from textwrap import dedent import streamlit @@ -34,7 +34,7 @@ from .utils import check_callback_rules, check_session_state_rules -FORM_DOCS_INFO = """ +FORM_DOCS_INFO: Final = """ For more information, refer to the [documentation for forms](https://docs.streamlit.io/library/api-reference/control-flow/st.form). diff --git a/lib/streamlit/elements/markdown.py b/lib/streamlit/elements/markdown.py index 5492ad740503..34af327ad4ee 100644 --- a/lib/streamlit/elements/markdown.py +++ b/lib/streamlit/elements/markdown.py @@ -79,7 +79,8 @@ def markdown(self, body: str, unsafe_allow_html: bool = False) -> "DeltaGenerato markdown_proto.body = clean_text(body) markdown_proto.allow_html = unsafe_allow_html - return self.dg._enqueue("markdown", markdown_proto) + dg = self.dg._enqueue("markdown", markdown_proto) + return cast("DeltaGenerator", dg) def header(self, body: str, anchor: Optional[str] = None) -> "DeltaGenerator": """Display text in header formatting. @@ -104,7 +105,8 @@ def header(self, body: str, anchor: Optional[str] = None) -> "DeltaGenerator": else: header_proto.body = f'

{clean_text(body)}

' header_proto.allow_html = True - return self.dg._enqueue("markdown", header_proto) + dg = self.dg._enqueue("markdown", header_proto) + return cast("DeltaGenerator", dg) def subheader(self, body: str, anchor: Optional[str] = None) -> "DeltaGenerator": """Display text in subheader formatting. @@ -130,7 +132,8 @@ def subheader(self, body: str, anchor: Optional[str] = None) -> "DeltaGenerator" subheader_proto.body = f'

{clean_text(body)}

' subheader_proto.allow_html = True - return self.dg._enqueue("markdown", subheader_proto) + dg = self.dg._enqueue("markdown", subheader_proto) + return cast("DeltaGenerator", dg) def code(self, body: str, language: Optional[str] = "python") -> "DeltaGenerator": """Display a code block with optional syntax highlighting. @@ -159,7 +162,8 @@ def code(self, body: str, language: Optional[str] = "python") -> "DeltaGenerator "body": body, } code_proto.body = clean_text(markdown) - return self.dg._enqueue("markdown", code_proto) + dg = self.dg._enqueue("markdown", code_proto) + return cast("DeltaGenerator", dg) def title(self, body: str, anchor: Optional[str] = None) -> "DeltaGenerator": """Display text in title formatting. @@ -187,7 +191,8 @@ def title(self, body: str, anchor: Optional[str] = None) -> "DeltaGenerator": else: title_proto.body = f'

{clean_text(body)}

' title_proto.allow_html = True - return self.dg._enqueue("markdown", title_proto) + dg = self.dg._enqueue("markdown", title_proto) + return cast("DeltaGenerator", dg) def caption(self, body: str, unsafe_allow_html: bool = False) -> "DeltaGenerator": """Display text in small font. @@ -230,7 +235,8 @@ def caption(self, body: str, unsafe_allow_html: bool = False) -> "DeltaGenerator caption_proto.body = clean_text(body) caption_proto.allow_html = unsafe_allow_html caption_proto.is_caption = True - return self.dg._enqueue("markdown", caption_proto) + dg = self.dg._enqueue("markdown", caption_proto) + return cast("DeltaGenerator", dg) def latex(self, body: Union[str, "sympy.Expr"]) -> "DeltaGenerator": # This docstring needs to be "raw" because of the backslashes in the @@ -264,7 +270,8 @@ def latex(self, body: Union[str, "sympy.Expr"]) -> "DeltaGenerator": latex_proto = MarkdownProto() latex_proto.body = "$$\n%s\n$$" % clean_text(body) - return self.dg._enqueue("markdown", latex_proto) + dg = self.dg._enqueue("markdown", latex_proto) + return cast("DeltaGenerator", dg) @property def dg(self) -> "DeltaGenerator": diff --git a/lib/streamlit/elements/text.py b/lib/streamlit/elements/text.py index d687cf0f4f7d..1c4fe2b197bb 100644 --- a/lib/streamlit/elements/text.py +++ b/lib/streamlit/elements/text.py @@ -39,9 +39,10 @@ def text(self, body: str) -> "DeltaGenerator": """ text_proto = TextProto() text_proto.body = clean_text(body) - return self.dg._enqueue("text", text_proto) + dg = self.dg._enqueue("text", text_proto) + return cast("DeltaGenerator", dg) @property def dg(self) -> "DeltaGenerator": """Get our DeltaGenerator.""" - return cast(DeltaGenerator, self) + return cast("DeltaGenerator", self) From e65edad8e22ded9c8a9218b7790275099c7089ab Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 14:37:33 +0200 Subject: [PATCH 10/16] Relax dg.text body type to Any --- lib/streamlit/elements/text.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/streamlit/elements/text.py b/lib/streamlit/elements/text.py index 1c4fe2b197bb..a7f530e937ba 100644 --- a/lib/streamlit/elements/text.py +++ b/lib/streamlit/elements/text.py @@ -12,10 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +from typing import Any from typing import cast from typing import TYPE_CHECKING -import streamlit from streamlit.proto.Text_pb2 import Text as TextProto from .utils import clean_text @@ -24,7 +24,7 @@ class TextMixin: - def text(self, body: str) -> "DeltaGenerator": + def text(self, body: Any) -> "DeltaGenerator": """Write fixed-width and preformatted text. Parameters From fc0559da8e7724893b35f69056c0c789a7d5f79d Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 14:53:14 +0200 Subject: [PATCH 11/16] Fix test --- lib/tests/streamlit/streamlit_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tests/streamlit/streamlit_test.py b/lib/tests/streamlit/streamlit_test.py index 071bc0569179..9e938a5c48c7 100644 --- a/lib/tests/streamlit/streamlit_test.py +++ b/lib/tests/streamlit/streamlit_test.py @@ -419,7 +419,7 @@ def test_st_help(self): el.doc_string.doc_string.startswith("Display text in header formatting.") ) self.assertEqual(el.doc_string.type, "") - self.assertEqual(el.doc_string.signature, "(body, anchor=None)") + self.assertEqual(el.doc_string.signature, "(body: str, anchor: Optional[str] = None) -> 'DeltaGenerator'") def test_st_image_PIL_image(self): """Test st.image with PIL image.""" From 75469da749076fa1cc292b1f170b550ab1f10769 Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 15:00:57 +0200 Subject: [PATCH 12/16] Formatting --- lib/tests/streamlit/streamlit_test.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/tests/streamlit/streamlit_test.py b/lib/tests/streamlit/streamlit_test.py index 9e938a5c48c7..922783ec2c17 100644 --- a/lib/tests/streamlit/streamlit_test.py +++ b/lib/tests/streamlit/streamlit_test.py @@ -419,7 +419,10 @@ def test_st_help(self): el.doc_string.doc_string.startswith("Display text in header formatting.") ) self.assertEqual(el.doc_string.type, "") - self.assertEqual(el.doc_string.signature, "(body: str, anchor: Optional[str] = None) -> 'DeltaGenerator'") + self.assertEqual( + el.doc_string.signature, + "(body: str, anchor: Optional[str] = None) -> 'DeltaGenerator'", + ) def test_st_image_PIL_image(self): """Test st.image with PIL image.""" From ac2172f7640e6ac9dc671688c11348c8fc1fdf05 Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 15:02:11 +0200 Subject: [PATCH 13/16] Use typing_extensions.Final for backwards compatibility --- lib/streamlit/elements/button.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/streamlit/elements/button.py b/lib/streamlit/elements/button.py index 28652b9b88a4..39f86828e3de 100644 --- a/lib/streamlit/elements/button.py +++ b/lib/streamlit/elements/button.py @@ -16,7 +16,8 @@ from streamlit.scriptrunner import ScriptRunContext, get_script_run_ctx from streamlit.type_util import Key, to_key -from typing import cast, Final, Optional, Union, BinaryIO, TextIO +from typing import cast, Optional, Union, BinaryIO, TextIO +from typing_extensions import Final from textwrap import dedent import streamlit From d09678774658073785f918ae13ec112376e9ab7e Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 15:25:58 +0200 Subject: [PATCH 14/16] Add special handling for python 3.6 --- lib/tests/streamlit/streamlit_test.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/tests/streamlit/streamlit_test.py b/lib/tests/streamlit/streamlit_test.py index 922783ec2c17..e41d7830b964 100644 --- a/lib/tests/streamlit/streamlit_test.py +++ b/lib/tests/streamlit/streamlit_test.py @@ -20,6 +20,7 @@ import os import io import re +import sys import time import textwrap import unittest @@ -419,10 +420,17 @@ def test_st_help(self): el.doc_string.doc_string.startswith("Display text in header formatting.") ) self.assertEqual(el.doc_string.type, "") - self.assertEqual( - el.doc_string.signature, - "(body: str, anchor: Optional[str] = None) -> 'DeltaGenerator'", - ) + if sys.version_info[1] == 6: + # Python 3.6 represents the signature slightly differently + self.assertEqual( + el.doc_string.signature, + "(body: str, anchor: Union[str, NoneType] = None) -> 'DeltaGenerator'", + ) + else: + self.assertEqual( + el.doc_string.signature, + "(body: str, anchor: Optional[str] = None) -> 'DeltaGenerator'", + ) def test_st_image_PIL_image(self): """Test st.image with PIL image.""" From adab27afebd25412ceb99e516f30f7a0ad998f57 Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Wed, 27 Apr 2022 15:38:26 +0200 Subject: [PATCH 15/16] Update special case to apply to python 3.7 --- lib/tests/streamlit/streamlit_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tests/streamlit/streamlit_test.py b/lib/tests/streamlit/streamlit_test.py index e41d7830b964..41fb9a718404 100644 --- a/lib/tests/streamlit/streamlit_test.py +++ b/lib/tests/streamlit/streamlit_test.py @@ -420,8 +420,8 @@ def test_st_help(self): el.doc_string.doc_string.startswith("Display text in header formatting.") ) self.assertEqual(el.doc_string.type, "") - if sys.version_info[1] == 6: - # Python 3.6 represents the signature slightly differently + if sys.version_info[1] == 7: + # Python 3.7 represents the signature slightly differently self.assertEqual( el.doc_string.signature, "(body: str, anchor: Union[str, NoneType] = None) -> 'DeltaGenerator'", From e8e194a99d3fe19f5b6afc38e19342db8689afef Mon Sep 17 00:00:00 2001 From: Harald Husum Date: Mon, 2 May 2022 09:33:08 +0200 Subject: [PATCH 16/16] Compact imports --- lib/streamlit/elements/alert.py | 3 +-- lib/streamlit/elements/markdown.py | 5 +---- lib/streamlit/elements/text.py | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/streamlit/elements/alert.py b/lib/streamlit/elements/alert.py index 306fab6762cd..a2742dc9894f 100644 --- a/lib/streamlit/elements/alert.py +++ b/lib/streamlit/elements/alert.py @@ -12,8 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import cast -from typing import TYPE_CHECKING +from typing import cast, TYPE_CHECKING from streamlit.proto.Alert_pb2 import Alert as AlertProto from .utils import clean_text diff --git a/lib/streamlit/elements/markdown.py b/lib/streamlit/elements/markdown.py index 34af327ad4ee..12b8eaef796f 100644 --- a/lib/streamlit/elements/markdown.py +++ b/lib/streamlit/elements/markdown.py @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import cast -from typing import Optional -from typing import TYPE_CHECKING -from typing import Union +from typing import cast, Optional, TYPE_CHECKING, Union from streamlit import type_util from streamlit.proto.Markdown_pb2 import Markdown as MarkdownProto diff --git a/lib/streamlit/elements/text.py b/lib/streamlit/elements/text.py index a7f530e937ba..ffc6367971f6 100644 --- a/lib/streamlit/elements/text.py +++ b/lib/streamlit/elements/text.py @@ -12,9 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Any -from typing import cast -from typing import TYPE_CHECKING +from typing import Any, cast, TYPE_CHECKING from streamlit.proto.Text_pb2 import Text as TextProto from .utils import clean_text