Skip to content

Commit

Permalink
Merge branch 'develop' into prototype/snowflake
Browse files Browse the repository at this point in the history
* develop: (21 commits)
  Remove branching imports and always import from typing_extensions (#4699)
  Add type annotations for media (#4706)
  Components adjustments (#4694)
  Type annotations for type_util (#4704)
  Add type annotations for utils (#4703)
  Argument types for iframe (#4707)
  Add type annotations for write (#4686)
  Add type annotations for doc_string (#4690)
  Add type annotations for progress (#4688)
  Add type annotations for exception (#4681)
  Add type annotations for plotly_chart (#4684)
  Wrap Markdown text when there's no word break (#4696)
  Add type annotations for __init__.py (#4687)
  Make typing-extensions and unconditional dependency (#4697)
  Add type annotations for balloons (#4679)
  Add type annotations for empty (#4680)
  Add type annotations for json (#4682)
  Add type annotations for layouts (#4683)
  Add type annotations for snow (#4685)
  Import Final from typing or typing_extensions depending on the Python version (#4692)
  ...
  • Loading branch information
tconkling committed May 10, 2022
2 parents d3a61a7 + af5a25b commit 82bf45b
Show file tree
Hide file tree
Showing 91 changed files with 380 additions and 222 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
Diff not rendered.
2 changes: 1 addition & 1 deletion frontend/package.json
@@ -1,6 +1,6 @@
{
"name": "streamlit-browser",
"version": "1.8.1",
"version": "1.9.0",
"private": true,
"homepage": "./",
"scripts": {
Expand Down
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Spinner component renders without crashing 1`] = `"<div class=\\"css-yprxax-StyledSpinnerContainer e17lx80j0\\"><div class=\\"css-yu1mjb-ThemedStyledSpinner e17lx80j1 \\"></div><div data-testid=\\"stMarkdownContainer\\" class=\\"css-1o5mqjl-StyledStreamlitMarkdown e16nr0p33\\"><p>Loading...</p></div></div>"`;
exports[`Spinner component renders without crashing 1`] = `"<div class=\\"css-yprxax-StyledSpinnerContainer e17lx80j0\\"><div class=\\"css-yu1mjb-ThemedStyledSpinner e17lx80j1 \\"></div><div data-testid=\\"stMarkdownContainer\\" class=\\"css-8npnmo-StyledStreamlitMarkdown e16nr0p33\\"><p>Loading...</p></div></div>"`;
6 changes: 4 additions & 2 deletions frontend/src/components/shared/Radio/Radio.tsx
Expand Up @@ -120,6 +120,8 @@ class Radio extends React.PureComponent<Props, State> {
},
RadioMarkOuter: {
style: ({ $checked }: { $checked: boolean }) => ({
width: "1rem",
height: "1rem",
backgroundColor:
$checked && !disabled
? colors.primary
Expand All @@ -128,8 +130,8 @@ class Radio extends React.PureComponent<Props, State> {
},
RadioMarkInner: {
style: ({ $checked }: { $checked: boolean }) => ({
height: $checked ? "6px" : "16px",
width: $checked ? "6px" : "16px",
height: $checked ? "6px" : ".75rem",
width: $checked ? "6px" : ".75rem",
}),
},
Label: {
Expand Down
Expand Up @@ -35,6 +35,10 @@ export const StyledStreamlitMarkdown = styled.div<
color: theme.colors.linkText,
},

p: {
wordWrap: "break-word",
},

li: {
margin: "0.2em 0 0.2em 1.2em",
padding: "0 0 0 0.6em",
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/widgets/Checkbox/Checkbox.tsx
Expand Up @@ -152,6 +152,8 @@ class Checkbox extends React.PureComponent<Props, State> {
borderTopRightRadius: radii.md,
borderBottomLeftRadius: radii.md,
borderBottomRightRadius: radii.md,
display: "flex",
alignItems: "center",
}),
},
Checkmark: {
Expand All @@ -167,6 +169,8 @@ class Checkbox extends React.PureComponent<Props, State> {

return {
outline: 0,
width: "1rem",
height: "1rem",
boxShadow:
$isFocusVisible && $checked
? `0 0 0 0.2rem ${transparentize(colors.primary, 0.5)}`
Expand Down
15 changes: 6 additions & 9 deletions frontend/src/theme/globalStyles.ts
Expand Up @@ -150,8 +150,7 @@ export const globalStyles = (theme: Theme): any => css`
padding: 1.25rem 0 1rem 0;
margin: 0;
// Set to 1.4 so it looks nice when wrapped.
line-height: 1.4;
line-height: 1.2;
}
h2 {
Expand All @@ -165,8 +164,7 @@ export const globalStyles = (theme: Theme): any => css`
padding: 1rem 0 1rem 0;
margin: 0;
// Set to 1.4 so it looks nice when wrapped.
line-height: 1.4;
line-height: 1.2;
}
h3 {
Expand All @@ -180,8 +178,7 @@ export const globalStyles = (theme: Theme): any => css`
padding: 0.5rem 0 1rem 0;
margin: 0;
// Set to 1.4 so it looks nice when wrapped.
line-height: 1.4;
line-height: 1.2;
}
h4 {
Expand All @@ -190,7 +187,7 @@ export const globalStyles = (theme: Theme): any => css`
color: ${theme.colors.headingColor};
padding: 0.75rem 0 1rem 0;
margin: 0;
line-height: 1.4;
line-height: 1.2;
}
h5 {
Expand All @@ -199,7 +196,7 @@ export const globalStyles = (theme: Theme): any => css`
color: ${theme.colors.headingColor};
padding: 0 0 1rem 0;
margin: 0;
line-height: 1.4;
line-height: 1.2;
}
h6 {
Expand All @@ -208,7 +205,7 @@ export const globalStyles = (theme: Theme): any => css`
color: ${theme.colors.headingColor};
padding: 0 0 1rem 0;
margin: 0;
line-height: 1.4;
line-height: 1.2;
}
// Abbreviations
Expand Down
2 changes: 1 addition & 1 deletion lib/Pipfile
Expand Up @@ -62,5 +62,5 @@ validators = "*"
# Without watchdog, we fallback to a polling file watcher to check for app changes.
watchdog = {version = "*", markers = "platform_system != 'Darwin'"}
gitpython = "!=3.1.19"
typing-extensions = { version = "*", markers = "python_version < '3.8'" }
typing-extensions = "*"
semver = "*"
2 changes: 1 addition & 1 deletion lib/setup.py
Expand Up @@ -34,7 +34,7 @@
)
sys.exit(exit_msg)

VERSION = "1.8.1" # PEP-440
VERSION = "1.9.0" # PEP-440

NAME = "streamlit"

Expand Down
42 changes: 28 additions & 14 deletions lib/streamlit/__init__.py
Expand Up @@ -53,9 +53,9 @@
# Give the package a version.
from importlib_metadata import version as _version

__version__ = _version("streamlit")
__version__: str = _version("streamlit")

from typing import NoReturn
from typing import Any, Dict, Iterator, List, NoReturn
import contextlib as _contextlib
import sys as _sys
import threading as _threading
Expand Down Expand Up @@ -89,10 +89,10 @@
# This is set to True inside cli._main_run(), and is False otherwise.
# If False, we should assume that DeltaGenerator functions are effectively
# no-ops, and adapt gracefully.
_is_running_with_streamlit = False
_is_running_with_streamlit: bool = False


def _update_logger():
def _update_logger() -> None:
_logger.set_log_level(_config.get_option("logger.level").upper())
_logger.update_formatter()
_logger.init_tornado_logs()
Expand Down Expand Up @@ -206,7 +206,7 @@ def _update_logger():
beta_columns = _main.beta_columns


def set_option(key: str, value) -> None:
def set_option(key: str, value: Any) -> None:
"""Set config option.
Currently, only the following config options can be set within the script itself:
Expand All @@ -228,7 +228,12 @@ def set_option(key: str, value) -> None:
The new value to assign to this config option.
"""
opt = _config._config_options_template[key]
try:
opt = _config._config_options_template[key]
except KeyError as ke:
raise StreamlitAPIException(
"Unrecognized config option: {key}".format(key=key)
) from ke
if opt.scriptable:
_config.set_option(key, value)
return
Expand All @@ -240,7 +245,7 @@ def set_option(key: str, value) -> None:
)


def experimental_show(*args):
def experimental_show(*args: Any) -> None:
"""Write arguments and *argument names* to your app for debugging purposes.
Show() has similar properties to write():
Expand Down Expand Up @@ -306,12 +311,21 @@ def experimental_show(*args):
markdown("**%s**" % escaped)
write(args[idx])

except Exception:
except Exception as raised_exc:
_, exc, exc_tb = _sys.exc_info()
if exc is None:
# Presumably, exc should never be None, but it is typed as
# Optional, and I don't know the internals of sys.exc_info() well
# enough to just use a cast here. Hence, the runtime check.
raise RuntimeError(
"Unexpected state: exc was None. If you see this message, "
"please create an issue at "
"https://github.com/streamlit/streamlit/issues"
) from raised_exc
exception(exc)


def experimental_get_query_params():
def experimental_get_query_params() -> Dict[str, List[str]]:
"""Return the query parameters that is currently showing in the browser's URL bar.
Returns
Expand All @@ -337,11 +351,11 @@ def experimental_get_query_params():
"""
ctx = _get_script_run_ctx()
if ctx is None:
return ""
return {}
return _parse.parse_qs(ctx.query_string)


def experimental_set_query_params(**query_params):
def experimental_set_query_params(**query_params: Any) -> None:
"""Set the query parameters that are shown in the browser's URL bar.
Parameters
Expand Down Expand Up @@ -372,7 +386,7 @@ def experimental_set_query_params(**query_params):


@_contextlib.contextmanager
def spinner(text: str = "In progress..."):
def spinner(text: str = "In progress...") -> Iterator[None]:
"""Temporarily displays a message while executing a block of code.
Parameters
Expand Down Expand Up @@ -432,7 +446,7 @@ def set_message():
message.empty()


def _transparent_write(*args):
def _transparent_write(*args: Any) -> Any:
"""This is just st.write, but returns the arguments you passed to it."""
write(*args)
if len(args) == 1:
Expand All @@ -443,7 +457,7 @@ def _transparent_write(*args):
# We want to show a warning when the user runs a Streamlit script without
# 'streamlit run', but we need to make sure the warning appears only once no
# matter how many times __init__ gets loaded.
_use_warning_has_been_displayed = False
_use_warning_has_been_displayed: bool = False


def _maybe_print_use_warning() -> None:
Expand Down
15 changes: 9 additions & 6 deletions lib/streamlit/elements/balloons.py
Expand Up @@ -12,14 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import cast
from typing import cast, TYPE_CHECKING

import streamlit
from streamlit.proto.Balloons_pb2 import Balloons as BalloonsProto

if TYPE_CHECKING:
from streamlit.delta_generator import DeltaGenerator


class BalloonsMixin:
def balloons(self):
def balloons(self) -> "DeltaGenerator":
"""Draw celebratory balloons.
Example
Expand All @@ -31,9 +33,10 @@ def balloons(self):
"""
balloons_proto = BalloonsProto()
balloons_proto.show = True
return self.dg._enqueue("balloons", balloons_proto)
dg = self.dg._enqueue("balloons", balloons_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)
8 changes: 4 additions & 4 deletions lib/streamlit/elements/button.py
Expand Up @@ -13,24 +13,24 @@
# limitations under the License.

import io
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_extensions import Final
from textwrap import dedent
from typing_extensions import Final

import streamlit
from streamlit.errors import StreamlitAPIException
from streamlit.proto.Button_pb2 import Button as ButtonProto
from streamlit.in_memory_file_manager import in_memory_file_manager
from streamlit.proto.DownloadButton_pb2 import DownloadButton as DownloadButtonProto
from streamlit.scriptrunner import ScriptRunContext, get_script_run_ctx
from streamlit.state import (
register_widget,
WidgetArgs,
WidgetCallback,
WidgetKwargs,
)
from streamlit.type_util import Key, to_key

from .form import current_form_id, is_in_form
from .utils import check_callback_rules, check_session_state_rules

Expand Down
28 changes: 17 additions & 11 deletions lib/streamlit/elements/doc_string.py
Expand Up @@ -15,27 +15,30 @@
"""Allows us to create and absorb changes (aka Deltas) to elements."""

import inspect
from typing import Any, cast, TYPE_CHECKING
from typing_extensions import Final

from typing import cast

import streamlit
from streamlit.proto.DocString_pb2 import DocString as DocStringProto
from streamlit.logger import get_logger

LOGGER = get_logger(__name__)
if TYPE_CHECKING:
from streamlit.delta_generator import DeltaGenerator


LOGGER: Final = get_logger(__name__)


CONFUSING_STREAMLIT_MODULES = (
CONFUSING_STREAMLIT_MODULES: Final = (
"streamlit.echo",
"streamlit.delta_generator",
"streamlit.legacy_caching.caching",
)

CONFUSING_STREAMLIT_SIG_PREFIXES = ("(element, ",)
CONFUSING_STREAMLIT_SIG_PREFIXES: Final = ("(element, ",)


class HelpMixin:
def help(self, obj):
def help(self, obj: Any) -> "DeltaGenerator":
"""Display object's doc string, nicely formatted.
Displays the doc string for this object.
Expand All @@ -61,15 +64,18 @@ def help(self, obj):
"""
doc_string_proto = DocStringProto()
_marshall(doc_string_proto, obj)
return self.dg._enqueue("doc_string", doc_string_proto)
return cast(
"DeltaGenerator",
self.dg._enqueue("doc_string", doc_string_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)


def _marshall(doc_string_proto, obj):
def _marshall(doc_string_proto: DocStringProto, obj: Any) -> None:
"""Construct a DocString object.
See DeltaGenerator.help for docs.
Expand Down

0 comments on commit 82bf45b

Please sign in to comment.