(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 | if attr is not None: |
| 305 | if isinstance(attr, property): |
| 306 | readonly = attr.fset is None |
| 307 | elif isinstance(attr, langhelpers.generic_fn_descriptor): |
| 308 | readonly = True |
| 309 | else: |
| 310 | readonly = not hasattr(attr, "__set__") |
| 311 | doc = textwrap.indent( |
| 312 | inject_docstring_text( |
| 313 | attr.__doc__, |
| 314 | textwrap.indent( |
| 315 | ".. container:: class_bases\n\n" |
| 316 | f" Proxied for the {target_cls_sphinx_name} " |
| 317 | "class \n" |
| 318 | f" on behalf of the {proxy_cls_sphinx_name} " |
| 319 | "class.", |
| 320 | " ", |
| 321 | ), |
| 322 | 1, |
| 323 | ), |
| 324 | " ", |
| 325 | ).lstrip() |
| 326 | else: |
| 327 | readonly = False |
| 328 | doc = ( |
| 329 | f"Proxy for the :attr:`{sphinx_symbol}.{name}` " |
| 330 | "attribute \n" |
| 331 | f" on behalf of the {proxy_cls_sphinx_name} " |
| 332 | "class.\n" |
| 333 | ) |
| 334 | |
| 335 | code = ( |
| 336 | "@property\n" |
| 337 | "def %(name)s(self) -> %(return_type)s:\n" |
| 338 | ' r"""%(doc)s\n """ # noqa: E501\n\n' |
| 339 | " return self._proxied.%(name)s\n\n" |
| 340 | ) % {"name": name, "doc": doc, "return_type": return_type} |
| 341 | |
| 342 | if not readonly: |
| 343 | code += ( |
| 344 | "@%(name)s.setter\n" |
| 345 | "def %(name)s(self, attr: %(return_type)s) -> None:\n" |
| 346 | " self._proxied.%(name)s = attr\n\n" |
| 347 | ) % {"name": name, "return_type": return_type} |
| 348 | |
| 349 | buf.write(textwrap.indent(code, " ")) |
| 350 | |
| 351 | for meth in methods: |
| 352 | instrument(buf, meth) |
no test coverage detected