-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
validation.py
108 lines (78 loc) · 3.3 KB
/
validation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#-----------------------------------------------------------------------------
# Copyright (c) 2012 - 2024, Anaconda, Inc., and Bokeh Contributors.
# All rights reserved.
#
# The full license is in the file LICENSE.txt, distributed with this software.
#-----------------------------------------------------------------------------
""" Provide the Instance property.
The Instance property is used to construct object graphs of Bokeh models,
where one Bokeh model refers to another.
"""
#-----------------------------------------------------------------------------
# Boilerplate
#-----------------------------------------------------------------------------
from __future__ import annotations
import logging # isort:skip
log = logging.getLogger(__name__)
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Standard library imports
from functools import wraps
# Bokeh imports
from .bases import Property
#-----------------------------------------------------------------------------
# Globals and constants
#-----------------------------------------------------------------------------
__all__ = (
'validate',
'without_property_validation',
)
#-----------------------------------------------------------------------------
# General API
#-----------------------------------------------------------------------------
class validate:
""" Control validation of bokeh properties
This can be used as a context manager, or as a normal callable
Args:
value (bool) : Whether validation should occur or not
Example:
.. code-block:: python
with validate(False): # do no validate while within this block
pass
validate(False) # don't validate ever
See Also:
:func:`~bokeh.core.property.bases.validation_on`: check the state of validation
:func:`~bokeh.core.properties.without_property_validation`: function decorator
"""
def __init__(self, value) -> None:
self.old = Property._should_validate
Property._should_validate = value
def __enter__(self):
pass
def __exit__(self, typ, value, traceback):
Property._should_validate = self.old
def without_property_validation(input_function):
""" Turn off property validation during update callbacks
Example:
.. code-block:: python
@without_property_validation
def update(attr, old, new):
# do things without validation
See Also:
:class:`~bokeh.core.properties.validate`: context mangager for more fine-grained control
"""
@wraps(input_function)
def func(*args, **kwargs):
with validate(False):
return input_function(*args, **kwargs)
return func
#-----------------------------------------------------------------------------
# Dev API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Private API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------