Skip to content

Commit

Permalink
Support evaluating annotations < 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
blackary committed Jun 13, 2023
1 parent b1370db commit a7521a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/streamlit_extras/chart_annotations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
from typing import Iterable

import altair as alt
import entrypoints
import pandas as pd
import streamlit as st

try:
from altair.utils.plugin_registry import NoSuchEntryPoint
except ImportError:
from entrypoints import NoSuchEntryPoint

try:
from streamlit import cache_data # streamlit >= 1.18.0
except ImportError:
Expand All @@ -17,7 +21,7 @@

try:
alt.themes.enable("streamlit")
except entrypoints.NoSuchEntryPoint:
except NoSuchEntryPoint:
st.altair_chart = partial(st.altair_chart, theme="streamlit")


Expand Down
14 changes: 12 additions & 2 deletions src/streamlit_extras/function_explorer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,19 @@ def get_arg_details(func) -> list[Argument]:
]
except TypeError:
signature = inspect.signature(func)
obj_globals = getattr(func, "__globals__", None)
obj_locals = None
return [
Argument(argument=k, type_hint=eval(v.annotation), default=v.default)
for k, v in signature.parameters.items()
Argument(
argument=key,
type_hint=(
value.annotation
if not isinstance(value.annotation, str)
else eval(value.annotation, obj_globals, obj_locals)
),
default=value.default,
)
for key, value in signature.parameters.items()
]


Expand Down

0 comments on commit a7521a5

Please sign in to comment.