MCPcopy Create free account
hub / github.com/microsoft/debugpy / of_type

Function of_type

src/debugpy/common/json.py:106–129  ·  view source on GitHub ↗

Returns a validator for a JSON property that requires it to have a value of the specified type. If optional=True, () is also allowed. The meaning of classinfo is the same as for isinstance().

(*classinfo, **kwargs)

Source from the content-addressed store, hash-verified

104
105
106def of_type(*classinfo, **kwargs):
107 """Returns a validator for a JSON property that requires it to have a value of
108 the specified type. If optional=True, () is also allowed.
109
110 The meaning of classinfo is the same as for isinstance().
111 """
112
113 assert len(classinfo)
114 optional = kwargs.pop("optional", False)
115 assert not len(kwargs)
116
117 def validate(value):
118 if (optional and value == ()) or isinstance(value, classinfo):
119 return value
120 else:
121 converted_value = _converter(value, classinfo)
122 if converted_value:
123 return converted_value
124
125 if not optional and value == ():
126 raise ValueError("must be specified")
127 raise TypeError("must be " + " or ".join(t.__name__ for t in classinfo))
128
129 return validate
130
131
132def default(default):

Callers 3

arrayFunction · 0.85
validateFunction · 0.85
objectFunction · 0.85

Calls 1

popMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…