MCPcopy Index your code
hub / github.com/apache/fory / _bind_static_method

Function _bind_static_method

python/pyfory/serializer.py:125–148  ·  view source on GitHub ↗
(obj, method_name)

Source from the content-addressed store, hash-verified

123
124
125def _bind_static_method(obj, method_name):
126 cls = obj if isinstance(obj, type) else obj.__class__
127 try:
128 attr = inspect.getattr_static(obj, method_name)
129 except AttributeError as exc:
130 raise ValueError(f"Cannot resolve method {method_name!r} safely") from exc
131
132 if isinstance(attr, staticmethod):
133 method = attr.__func__
134 elif isinstance(attr, classmethod):
135 method = types.MethodType(attr.__func__, cls)
136 elif isinstance(attr, types.FunctionType):
137 method = types.MethodType(attr, obj)
138 elif isinstance(attr, (types.MethodType, types.BuiltinMethodType)):
139 method = attr
140 elif isinstance(attr, (types.MethodDescriptorType, types.WrapperDescriptorType)):
141 method = attr.__get__(obj, cls)
142 elif callable(attr) and not hasattr(type(attr), "__get__"):
143 method = attr
144 else:
145 raise ValueError(f"Cannot resolve method {method_name!r} safely")
146 if not callable(method):
147 raise ValueError(f"Resolved method {method_name!r} is not callable")
148 return method
149
150
151def _resolve_validated_bound_method(policy, obj, method_name, is_local):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected