MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / makeprop

Function makeprop

tools/generate_proxy_methods.py:295–361  ·  view source on GitHub ↗
(buf: TextIO, name: str)

Source from the content-addressed store, hash-verified

293 buf.write(textwrap.indent(code, " "))
294
295 def makeprop(buf: TextIO, name: str) -> None:
296 attr = target_cls.__dict__.get(name, None)
297
298 return_type = target_cls.__annotations__.get(name, "Any")
299 assert isinstance(return_type, str), (
300 "expected string annotations, is from __future__ "
301 "import annotations set up?"
302 )
303
304 existing_doc = None
305
306 if attr is not None:
307 if isinstance(attr, property):
308 readonly = attr.fset is None
309 existing_doc = attr.__doc__
310 elif isinstance(attr, langhelpers.generic_fn_descriptor):
311 readonly = True
312 existing_doc = attr.__doc__
313 elif hasattr(attr, "__get__"):
314 readonly = not hasattr(attr, "__set__")
315 existing_doc = attr.__doc__
316 else:
317 # not a descriptor
318 readonly = False
319
320 else:
321 readonly = False
322
323 if existing_doc:
324 doc = textwrap.indent(
325 inject_docstring_text(
326 attr.__doc__,
327 textwrap.indent(
328 ".. container:: class_bases\n\n"
329 f" Proxied for the {target_cls_sphinx_name} "
330 "class \n"
331 f" on behalf of the {proxy_cls_sphinx_name} "
332 "class.",
333 " ",
334 ),
335 1,
336 ),
337 " ",
338 ).lstrip()
339 else:
340 doc = (
341 f"Proxy for the :attr:`{sphinx_symbol}.{name}` "
342 "attribute \n"
343 f" on behalf of the {proxy_cls_sphinx_name} "
344 "class.\n"
345 )
346
347 code = (
348 "@property\n"
349 "def %(name)s(self) -> %(return_type)s:\n"
350 ' r"""%(doc)s\n """ # noqa: E501\n\n'
351 " return self._proxied.%(name)s\n\n"
352 ) % {"name": name, "doc": doc, "return_type": return_type}

Callers 1

process_classFunction · 0.85

Calls 4

inject_docstring_textFunction · 0.90
lstripMethod · 0.80
getMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected