Skip to content

Commit adb8d50

Browse files
authored
Merge branch 'dev' into make-targetable-tooltip-interactive
2 parents c5b8701 + f7bb866 commit adb8d50

File tree

8 files changed

+32
-34
lines changed

8 files changed

+32
-34
lines changed

dash/_callback.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import collections
22
import hashlib
3+
import inspect
34
from functools import wraps
45

56
from typing import Callable, Optional, Any, List, Tuple, Union, Dict
67

7-
8-
import asyncio
98
import flask
109

1110
from .dependencies import (
@@ -49,7 +48,7 @@ async def _async_invoke_callback(
4948
func, *args, **kwargs
5049
): # used to mark the frame for the debugger
5150
# Check if the function is a coroutine function
52-
if asyncio.iscoroutinefunction(func):
51+
if inspect.iscoroutinefunction(func):
5352
return await func(*args, **kwargs) # %% callback invoked %%
5453
# If the function is not a coroutine, call it directly
5554
return func(*args, **kwargs) # %% callback invoked %%
@@ -814,7 +813,7 @@ async def async_add_context(*args, **kwargs):
814813

815814
return jsonResponse
816815

817-
if asyncio.iscoroutinefunction(func):
816+
if inspect.iscoroutinefunction(func):
818817
callback_map[callback_id]["callback"] = async_add_context
819818
else:
820819
callback_map[callback_id]["callback"] = add_context

dash/_jupyter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def capture_event(stream, ident, parent):
202202
if _jupyter_comm_response_received():
203203
break
204204

205-
if asyncio.iscoroutinefunction(kernel.do_one_iteration):
205+
if inspect.iscoroutinefunction(kernel.do_one_iteration):
206206
loop = asyncio.get_event_loop()
207207
nest_asyncio.apply(loop)
208208
loop.run_until_complete(kernel.do_one_iteration())

dash/background_callback/managers/celery_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
import json
23
import traceback
34
from contextvars import copy_context
@@ -250,7 +251,7 @@ async def async_run():
250251
result_key, json.dumps(user_callback_output, cls=PlotlyJSONEncoder)
251252
)
252253

253-
if asyncio.iscoroutinefunction(fn):
254+
if inspect.iscoroutinefunction(fn):
254255
func = partial(ctx.run, async_run)
255256
asyncio.run(func())
256257
else:

dash/background_callback/managers/diskcache_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
import traceback
23
from contextvars import copy_context
34
import asyncio
@@ -296,7 +297,7 @@ async def async_run():
296297
except Exception as err: # pylint: disable=broad-except
297298
print(f"Diskcache manager couldn't save output: {err}")
298299

299-
if asyncio.iscoroutinefunction(fn):
300+
if inspect.iscoroutinefunction(fn):
300301
func = partial(ctx.run, async_run)
301302
asyncio.run(func())
302303
else:

dash/dash.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
import collections
5+
import inspect
56
import importlib
67
import warnings
78
from contextvars import copy_context
@@ -220,7 +221,7 @@ def _do_skip(error):
220221

221222
async def execute_async_function(func, *args, **kwargs):
222223
# Check if the function is a coroutine function
223-
if asyncio.iscoroutinefunction(func):
224+
if inspect.iscoroutinefunction(func):
224225
return await func(*args, **kwargs)
225226
# If the function is not a coroutine, call it directly
226227
return func(*args, **kwargs)
@@ -837,7 +838,7 @@ async def _parse_body_async():
837838
return _parse_body_async
838839

839840
for path, func in self.callback_api_paths.items():
840-
if asyncio.iscoroutinefunction(func):
841+
if inspect.iscoroutinefunction(func):
841842
self._add_url(path, make_parse_body_async(func), ["POST"])
842843
else:
843844
self._add_url(path, make_parse_body(func), ["POST"])

dash/dependencies.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from enum import Enum
12
from typing import Union, Sequence, Any
23

34
from .development.base_component import Component
@@ -9,32 +10,33 @@
910
ComponentIdType = Union[str, Component, dict]
1011

1112

12-
class _Wildcard: # pylint: disable=too-few-public-methods
13-
def __init__(self, name: str):
14-
self._name = name
13+
class Wildcard(Enum):
14+
MATCH = "MATCH"
15+
ALL = "ALL"
16+
ALLSMALLER = "ALLSMALLER"
1517

1618
def __str__(self):
17-
return self._name
19+
return self.value
1820

1921
def __repr__(self):
20-
return f"<{self}>"
22+
return f"<{self.value}>"
2123

2224
def to_json(self) -> str:
2325
# used in serializing wildcards - arrays are not allowed as
2426
# id values, so make the wildcards look like length-1 arrays.
25-
return f'["{self._name}"]'
27+
return f'["{self.value}"]'
2628

2729

28-
MATCH = _Wildcard("MATCH")
29-
ALL = _Wildcard("ALL")
30-
ALLSMALLER = _Wildcard("ALLSMALLER")
30+
MATCH = Wildcard.MATCH
31+
ALL = Wildcard.ALL
32+
ALLSMALLER = Wildcard.ALLSMALLER
3133

3234

3335
class DashDependency: # pylint: disable=too-few-public-methods
3436
component_id: ComponentIdType
3537
allow_duplicate: bool
3638
component_property: str
37-
allowed_wildcards: Sequence[_Wildcard]
39+
allowed_wildcards: Sequence[Wildcard]
3840
allow_optional: bool
3941

4042
def __init__(self, component_id: ComponentIdType, component_property: str):
@@ -95,8 +97,8 @@ def _id_matches(self, other) -> bool:
9597
other_v = other_id[k]
9698
if v == other_v:
9799
continue
98-
v_wild = isinstance(v, _Wildcard)
99-
other_wild = isinstance(other_v, _Wildcard)
100+
v_wild = isinstance(v, Wildcard)
101+
other_wild = isinstance(other_v, Wildcard)
100102
if v_wild or other_wild:
101103
if not (v_wild and other_wild):
102104
continue # one wild, one not
@@ -120,7 +122,7 @@ def has_wildcard(self) -> bool:
120122
"""
121123
if isinstance(self.component_id, dict):
122124
for v in self.component_id.values():
123-
if isinstance(v, _Wildcard):
125+
if isinstance(v, Wildcard):
124126
return True
125127
return False
126128

dash/development/_py_components_generation.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@
2525
from typing_extensions import TypedDict, NotRequired, Literal # noqa: F401
2626
from dash.development.base_component import Component, _explicitize_args
2727
{custom_imports}
28+
ComponentSingleType = typing.Union[str, int, float, Component, None]
2829
ComponentType = typing.Union[
29-
str,
30-
int,
31-
float,
32-
Component,
33-
None,
34-
typing.Sequence[typing.Union[str, int, float, Component, None]],
30+
ComponentSingleType,
31+
typing.Sequence[ComponentSingleType],
3532
]
3633
3734
NumberType = typing.Union[

dash/development/base_component.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,11 @@ def _validate_deprecation(self):
454454
warnings.warn(DeprecationWarning(textwrap.dedent(deprecation_message)))
455455

456456

457+
ComponentSingleType = typing.Union[str, int, float, Component, None]
457458
# Renderable node type.
458459
ComponentType = typing.Union[
459-
str,
460-
int,
461-
float,
462-
Component,
463-
None,
464-
typing.Sequence[typing.Union[str, int, float, Component, None]],
460+
ComponentSingleType,
461+
typing.Sequence[ComponentSingleType],
465462
]
466463

467464
ComponentTemplate = typing.TypeVar("ComponentTemplate")

0 commit comments

Comments
 (0)