(buf: TextIO, name: str)
| 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} |
no test coverage detected