MCPcopy
hub / github.com/reflex-dev/reflex / _deps

Method _deps

packages/reflex-base/src/reflex_base/vars/base.py:2527–2576  ·  view source on GitHub ↗

Determine var dependencies of this ComputedVar. Save references to attributes accessed on "self" or other fetched states. Recursively called when the function makes a method call on "self" or define comprehensions or nested functions that may reference "self". Args

(
        self,
        objclass: type[BaseState],
        obj: FunctionType | CodeType | None = None,
    )

Source from the content-addressed store, hash-verified

2525 )
2526
2527 def _deps(
2528 self,
2529 objclass: type[BaseState],
2530 obj: FunctionType | CodeType | None = None,
2531 ) -> dict[str, set[str]]:
2532 """Determine var dependencies of this ComputedVar.
2533
2534 Save references to attributes accessed on "self" or other fetched states.
2535
2536 Recursively called when the function makes a method call on "self" or
2537 define comprehensions or nested functions that may reference "self".
2538
2539 Args:
2540 objclass: the class obj this ComputedVar is attached to.
2541 obj: the object to disassemble (defaults to the fget function).
2542
2543 Returns:
2544 A dictionary mapping state names to the set of variable names
2545 accessed by the given obj.
2546 """
2547 from .dep_tracking import DependencyTracker
2548
2549 d = {}
2550 if self._static_deps:
2551 d.update(self._static_deps)
2552 # None is a placeholder for the current state class.
2553 if None in d:
2554 d[objclass.get_full_name()] = d.pop(None)
2555
2556 if not self._auto_deps:
2557 return d
2558
2559 if obj is None:
2560 fget = self._fget
2561 if fget is not None:
2562 obj = cast(FunctionType, fget)
2563 else:
2564 return d
2565
2566 try:
2567 return DependencyTracker(
2568 func=obj, state_cls=objclass, dependencies=d
2569 ).dependencies
2570 except Exception as e:
2571 console.warn(
2572 "Failed to automatically determine dependencies for computed var "
2573 f"{objclass.__name__}.{self._name}: {e}. "
2574 "Set auto_deps=False and provide accurate deps=['var1', 'var2'] to suppress this warning."
2575 )
2576 return d
2577
2578 def mark_dirty(self, instance: BaseState) -> None:
2579 """Mark this ComputedVar as dirty.

Calls 3

DependencyTrackerClass · 0.85
get_full_nameMethod · 0.80
updateMethod · 0.45