MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / process_class

Function process_class

tools/generate_proxy_methods.py:178–370  ·  view source on GitHub ↗
(
    buf: TextIO,
    target_cls: Type[Any],
    target_cls_sphinx_name: str,
    proxy_cls_sphinx_name: str,
    classmethods: Iterable[str],
    methods: Iterable[str],
    attributes: Iterable[str],
    use_intermediate_variable: Iterable[str],
    cls: Type[Any],
)

Source from the content-addressed store, hash-verified

176
177
178def process_class(
179 buf: TextIO,
180 target_cls: Type[Any],
181 target_cls_sphinx_name: str,
182 proxy_cls_sphinx_name: str,
183 classmethods: Iterable[str],
184 methods: Iterable[str],
185 attributes: Iterable[str],
186 use_intermediate_variable: Iterable[str],
187 cls: Type[Any],
188):
189 sphinx_symbol_match = re.match(r":class:`(.+)`", target_cls_sphinx_name)
190 if not sphinx_symbol_match:
191 raise Exception(
192 f"Couldn't match sphinx class identifier from "
193 f"target_cls_sphinx_name f{target_cls_sphinx_name!r}. Currently "
194 'this program expects the form ":class:`_<prefix>.<clsname>`"'
195 )
196
197 sphinx_symbol = sphinx_symbol_match.group(1)
198
199 require_intermediate = set(use_intermediate_variable)
200
201 def instrument(buf: TextIO, name: str, clslevel: bool = False) -> None:
202 fn = getattr(target_cls, name)
203
204 overloads = _grab_overloads(fn)
205
206 for overload in overloads:
207 buf.write(overload)
208
209 spec = compat.inspect_getfullargspec(fn)
210
211 iscoroutine = inspect.iscoroutinefunction(fn)
212
213 if spec.defaults or spec.kwonlydefaults:
214 elem = list(spec)
215
216 if spec.defaults:
217 new_defaults = tuple(
218 (
219 _repr_sym("util.EMPTY_DICT")
220 if df is util.EMPTY_DICT
221 else df
222 )
223 for df in spec.defaults
224 )
225 elem[3] = new_defaults
226
227 if spec.kwonlydefaults:
228 new_kwonlydefaults = {
229 name: (
230 _repr_sym("util.EMPTY_DICT")
231 if df is util.EMPTY_DICT
232 else df
233 )
234 for name, df in spec.kwonlydefaults.items()
235 }

Callers 1

process_moduleFunction · 0.85

Calls 3

instrumentFunction · 0.85
makepropFunction · 0.85
matchMethod · 0.45

Tested by

no test coverage detected