1
1
from __future__ import annotations
2
2
3
3
import inspect
4
- import abc
5
4
import logging
6
5
import re
7
6
from collections .abc import Collection , Iterable , Mapping
8
7
from pprint import pformat
9
- from typing import Annotated , Any , NewType , TypedDict , Union , cast , Callable
8
+ from typing import Annotated , Any , Literal , NewType , TypedDict , Union , cast
10
9
11
10
from dash import Input , Output , State , callback , html
12
11
from dash .development .base_component import Component
16
15
from vizro .managers ._model_manager import ModelID , model_manager
17
16
from vizro .models import VizroBaseModel
18
17
from vizro .models ._models_utils import _log_call
19
- from vizro .models .types import CapturedCallable , ControlType , capture , validate_captured_callable
20
-
21
- from typing import Literal
18
+ from vizro .models .types import CapturedCallable , ControlType , validate_captured_callable
22
19
23
20
logger = logging .getLogger (__name__ )
24
21
@@ -37,7 +34,6 @@ class Controls(TypedDict):
37
34
filter_interaction : list [dict [str , Any ]]
38
35
39
36
40
- # TODO NOW: probably split into one model per file structure
41
37
class _BaseAction (VizroBaseModel ):
42
38
def _get_control_states (self , control_type : ControlType ) -> list [State ]:
43
39
"""Gets list of `States` for selected `control_type` that appear on page where this Action is defined."""
@@ -322,62 +318,3 @@ def _runtime_args(self) -> dict[str, IdProperty]:
322
318
@property
323
319
def _action_name (self ):
324
320
return self .function ._function .__name__
325
-
326
-
327
- class AbstractAction (_BaseAction , abc .ABC ):
328
- """AbstractAction to be inserted into `actions` of relevant component.
329
-
330
- To use this class, you must subclass it and define `function` and `outputs` to make a concrete action class. All
331
- built in actions follow this pattern, and it's also an option for user-defined acftions. This class is not
332
- relevant for user-defined actions using @capture("action").
333
-
334
- When subclassing, you can optionally define model fields. The handling of fields depends on whether it is also
335
- present in the function signature:
336
- - static arguments, e.g. file_format = "csv": model fields, not explicitly in function signature, go through self.
337
- Uses self and not Dash State
338
- - runtime arguments, e.g. arg_name="dropdown.value": model fields, explicitly in function signature. Uses Dash
339
- State
340
- - built in runtime arguments, e.g. controls: not model fields, explicitly in function signature. Uses Dash State
341
- """
342
-
343
- _legacy = False
344
-
345
- # TODO NOW COMMENT: Check schema and make sure these don't appear, comment on importance of this.
346
-
347
- # TODO NOW: make keyword args only? What are actual limitations here? Don't worry much about it.
348
- @abc .abstractmethod
349
- def function (self , * args , ** kwargs ):
350
- """Function that must be defined by concrete action."""
351
- pass
352
-
353
- @property
354
- @abc .abstractmethod
355
- def outputs (self ) -> dict [str , IdProperty ]:
356
- """Must be defined by concrete action, even if there's no output."""
357
- # TODO NOW OR IN FUTURE: handle list[str], align with Action. Maybe allow more deeply nested things too.
358
- # TODO NOW: should it handle dictionary ids too? Currently this needs overriding _get_outputs. Pattern matching
359
- # probably not needed for outputs and only for built-in inputs. Even if add more functionality here in future
360
- # we shoulod still at least the support same as Action.output so it's easy for someone to move from a function
361
- # action to a class one. In future we'd even like to just allow specifying the component id without the property.
362
-
363
- # Maybe there will be some special built-in behaviour here e.g. to generate outputs automatically from
364
- # certain reserved arguments like self.targets. Would need to make sure it's not breaking if someone already
365
- # uses that variable name though.
366
- pass
367
-
368
- @property
369
- def _parameters (self ) -> set [str ]:
370
- # Note order of parameters doesn't matter since we always handle things with keyword arguments.
371
- return set (inspect .signature (self .function ).parameters )
372
-
373
- @property
374
- def _runtime_args (self ) -> dict [str , IdProperty ]:
375
- # Since function is not a CapturedCallable, input arguments have not yet been bound. They correspond to the
376
- # model fields that are present in the function signature. This is just the user-specified runtime arguments, as
377
- # static arguments are not in the function signature (they're in self) and built in runtime arguments are not
378
- # model fields. These will be of the form {"argument_name": "dropdown.value"}.
379
- return {arg_name : getattr (self , arg_name ) for arg_name in self .model_fields if arg_name in self ._parameters }
380
-
381
- @property
382
- def _action_name (self ):
383
- return self .__class__ .__name__
0 commit comments