state: Leading underscore functions are not backend vars (#1268)
This commit is contained in:
parent
3b3fc4f965
commit
cd63297fe4
@ -10,6 +10,7 @@ import traceback
|
||||
import urllib.parse
|
||||
from abc import ABC
|
||||
from collections import defaultdict
|
||||
from types import FunctionType
|
||||
from typing import (
|
||||
Any,
|
||||
AsyncIterator,
|
||||
@ -197,6 +198,7 @@ class State(Base, ABC, extra=pydantic.Extra.allow):
|
||||
for name, value in cls.__dict__.items()
|
||||
if types.is_backend_variable(name)
|
||||
and name not in cls.inherited_backend_vars
|
||||
and not isinstance(value, FunctionType)
|
||||
}
|
||||
|
||||
cls.backend_vars = {**cls.inherited_backend_vars, **cls.new_backend_vars}
|
||||
|
@ -1087,3 +1087,18 @@ def test_computed_var_depends_on_parent_non_cached():
|
||||
IS_HYDRATED: False,
|
||||
}
|
||||
assert counter == 6
|
||||
|
||||
|
||||
def test_backend_method():
|
||||
"""A method with leading underscore should be callable from event handler."""
|
||||
|
||||
class BackendMethodState(State):
|
||||
def _be_method(self):
|
||||
return True
|
||||
|
||||
def handler(self):
|
||||
assert self._be_method()
|
||||
|
||||
bms = BackendMethodState()
|
||||
bms.handler()
|
||||
assert bms._be_method()
|
||||
|
Loading…
Reference in New Issue
Block a user