Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type annotations for utils #4703

Merged
merged 2 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/streamlit/elements/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def clean_text(text: Any) -> str:
return textwrap.dedent(str(text)).strip()


def last_index_for_melted_dataframes(data):
def last_index_for_melted_dataframes(data: Any) -> Any:
if type_util.is_dataframe_compatible(data):
data = type_util.convert_anything_to_df(data)

Expand All @@ -55,7 +55,7 @@ def check_callback_rules(
)


_shown_default_value_warning = False
_shown_default_value_warning: bool = False


def check_session_state_rules(
Expand Down
12 changes: 8 additions & 4 deletions lib/streamlit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
import os
import subprocess

from typing import Any, List
from typing import Any, Dict, List, TypeVar
from typing_extensions import Final

from streamlit import env_util

# URL of Streamlit's help page.
HELP_DOC = "https://docs.streamlit.io/"
HELP_DOC: Final = "https://docs.streamlit.io/"


def memoize(func):
Expand Down Expand Up @@ -94,7 +95,7 @@ def _open_browser_with_command(command, url):
subprocess.Popen(cmd_line, stdout=devnull, stderr=subprocess.STDOUT)


def _maybe_tuple_to_list(item):
def _maybe_tuple_to_list(item: Any) -> Any:
"""Convert a tuple to a list. Leave as is if it's not a tuple."""
if isinstance(item, tuple):
return list(item)
Expand Down Expand Up @@ -129,7 +130,10 @@ def index_(iterable, x) -> int:
raise ValueError("{} is not in iterable".format(str(x)))


def lower_clean_dict_keys(dict):
_Value = TypeVar("_Value")


def lower_clean_dict_keys(dict: Dict[str, _Value]) -> Dict[str, _Value]:
return {k.lower().strip(): v for k, v in dict.items()}


Expand Down