| 309 | |
| 310 | |
| 311 | def _decorate_cls_with_warning( |
| 312 | cls: Type[_T], |
| 313 | constructor: Optional[str], |
| 314 | wtype: Type[exc.SADeprecationWarning], |
| 315 | message: str, |
| 316 | version: str, |
| 317 | docstring_header: Optional[str] = None, |
| 318 | ) -> Type[_T]: |
| 319 | doc = cls.__doc__ is not None and cls.__doc__ or "" |
| 320 | if docstring_header is not None: |
| 321 | if constructor is not None: |
| 322 | docstring_header %= dict(func=constructor) |
| 323 | |
| 324 | if issubclass(wtype, exc.Base20DeprecationWarning): |
| 325 | docstring_header += ( |
| 326 | " (Background on SQLAlchemy 2.0 at: " |
| 327 | ":ref:`migration_20_toplevel`)" |
| 328 | ) |
| 329 | doc = inject_docstring_text(doc, docstring_header, 1) |
| 330 | |
| 331 | constructor_fn = None |
| 332 | if type(cls) is type: |
| 333 | clsdict = dict(cls.__dict__) |
| 334 | clsdict["__doc__"] = doc |
| 335 | clsdict.pop("__dict__", None) |
| 336 | clsdict.pop("__weakref__", None) |
| 337 | cls = type(cls.__name__, cls.__bases__, clsdict) |
| 338 | if constructor is not None: |
| 339 | constructor_fn = clsdict[constructor] |
| 340 | |
| 341 | else: |
| 342 | cls.__doc__ = doc |
| 343 | if constructor is not None: |
| 344 | constructor_fn = getattr(cls, constructor) |
| 345 | |
| 346 | if constructor is not None: |
| 347 | assert constructor_fn is not None |
| 348 | assert wtype is not None |
| 349 | setattr( |
| 350 | cls, |
| 351 | constructor, |
| 352 | _decorate_with_warning( |
| 353 | constructor_fn, wtype, message, version, None |
| 354 | ), |
| 355 | ) |
| 356 | return cls |
| 357 | |
| 358 | |
| 359 | def _decorate_with_warning( |