o znh@sdZddlZddlZddlmZddlmZddlmZddlmZdd lm Z d!d d Z d!d dZ d"ddZ d#ddZ ddZ d#ddZddZddZ d$ddZd$dd ZdS)%zSHelpers related to deprecation of functions, methods, classes, other functionality.N)compat) decorator)inject_docstring_text)inject_param_text)exccCtj|tj|ddSN stacklevelwarningswarnrSADeprecationWarningmsgr rG/usr/local/lib/python3.10/dist-packages/sqlalchemy/util/deprecations.pywarn_deprecatedrcCr r )rrrSAPendingDeprecationWarningrrrrwarn_pending_deprecationrr__init__cs$d|pdffdd}|S)N.. deprecated:: %s %scst|tjtdSNfunc)_decorate_cls_with_warningrrdict)cls constructorheadermessagerrdecorate s z deprecated_cls..decorater)versionr&r$r'rr#rdeprecated_clss r)Tc8|r d|pdfnddurdfdd}|S)aDecorates a function and issues a deprecation warning on use. :param version: Issue version in the warning. :param message: If provided, issue message in the warning. A sensible default is used if not provided. :param add_deprecation_to_docstring: Default True. If False, the wrapped function's __doc__ is left as-is. If True, the 'message' is prepended to the docs if provided, or sensible default if message is omitted. rrN$Call to deprecated function %(func)sct|tjt|jdSr)_decorate_with_warningrrr!__name__fnr%r&rrr'E zdeprecated..decoraterr(r&add_deprecation_to_docstringr'rr1r deprecated,sr5c s8iD] \}\}}t||<qfdd}|S)a"Decorates a function to warn on use of certain parameters. e.g. :: @deprecated_params( weak_identity_map=( "0.7", "the :paramref:`.Session.weak_identity_map parameter " "is deprecated." ) ) cst|}|jdur.tt|jt|jt|jd|jtt ndtt fdd}|j durG|j pHd}|rWt |dd D}||}||_ |S)NrcsfD]}|||krtj|tjddqD]}||vr+tj|tjddq||i|SNr r r)r0argskwargsm)check_defaultscheck_kwdefaultsmessagesrrwarnedss  z3deprecated_params..decorate..warnedrcSs&i|]\}\}}|d||pdfqS)rrr).0paramr(r&rrr s z7deprecated_params..decorate..)rinspect_getfullargspecr<r!zipr7lenset intersection differencer__doc__ritems)r0specr>doc decoratedr=specs)r:r;r<rr'ds2  z#deprecated_params..decorate)rI_sanitize_restructured_text)rNr@r(r&r'rrMrdeprecated_paramsPs +rPcr*)aEDecorates a function and issues a pending deprecation warning on use. :param version: An approximate future version at which point the pending deprecation will become deprecated. Not used in messaging. :param message: If provided, issue message in the warning. A sensible default is used if not provided. :param add_deprecation_to_docstring: Default True. If False, the wrapped function's __doc__ is left as-is. If True, the 'message' is prepended to the docs if provided, or sensible default if message is omitted. z.. deprecated:: %s (pending) %srNr+cr,r)r-rrr!r.r/r1rrr'r2z%pending_deprecation..decoraterr3rr1rpending_deprecationsrQcCs|dur|St||SN)r)parameter_value default_value warning_textrrrdeprecated_option_valuesrVcCsdd}td||S)NcSs$|dd\}}|dvr|d7}|S)Nrr)rmethz())group)r9type_namerrrreplsz)_sanitize_restructured_text..replz\:(\w+)\:`~?\.?(.+?)`)resub)textr[rrrrOsrOcCs|jdur|jp d}|dur?|t|d;}t||d}t|tur7t|j}||d<t|j|j|}||}n||_t||}t||t |||d|S)NrrrrH) rHr!rtype__dict__r. __bases__getattrsetattrr-)r"r$wtyper&docstring_headerrKclsdictconstructor_fnrrrr s"      r cstttfdd}|jdur|jpd}|dur)|t|jd;}t||d}||}||_fdd|_|S) z=Wrap a function with a warnings.warn and augmented docstring.cstjdd||i|Sr6rr)r0r7r8r&rdrrr>sz&_decorate_with_warning..warnedNrrrcstjddSr6rhrrirrsz(_decorate_with_warning..)rOrrHr!r.r_sa_warn)rrdr&rer>rKrLrrirr-s r-)r )r)NTrR)rHr\rrr langhelpersrrrrrrr)r5rPrQrVrOr r-rrrrs(         $C &