o  i9@sddlmZddlZddlZddlZddlmZddlmZddl m Z ddl m Z m Z ddlmZdd lmZgd Ze d eeZGd d d eZefddZdddeefd'ddZdddedefd(dd Zdddeefd)d%d&ZdS)*) annotationsN)Callable)wraps) FunctionType)AnyTypeVar) version_leq) __version__) deprecateddeprecated_argDeprecatedErrordeprecated_arg_defaultTc@s eZdZdS)r N)__name__ __module__ __qualname__rr]/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/utils/deprecate_utils.pyr sr cCstj|d||dddS)z* Issue the warning message `msg`. z: r )category stacklevelN)warningswarn)objmsgwarning_categoryrrrwarn_deprecated"srsince str | Noneremoved msg_suffixstr version_valrtype[FutureWarning]returnCallable[[T], T]csdurdurtstdddduo$|ko$t|}|r+ddSdur8dur8ddnduo@t|duoIt|fdd }|S) a* Marks a function or class as deprecated. If `since` is given this should be a version at or earlier than the current version and states at what version of the definition was marked as deprecated. If `removed` is given this can be any version and marks when the definition was removed. When the decorated definition is called, that is when the function is called or the class instantiated, a `warning_category` is issued if `since` is given and the current version is at or later than that given. a `DeprecatedError` exception is instead raised if `removed` is given and the current version is at or later than that, or if neither `since` nor `removed` is provided. The relevant docstring of the deprecating function should also be updated accordingly, using the Sphinx directives such as `.. versionchanged:: version` and `.. deprecated:: version`. https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-versionadded Args: since: version at which the definition was marked deprecated but not removed. removed: version at which the definition was/will be removed and no longer usable. msg_suffix: message appended to warning/exception detailing reasons for deprecation and what to use instead. version_val: (used for testing) version to compare since and removed against, default is MONAI version. warning_category: a warning category class, defaults to `FutureWarning`. Returns: Decorated definition which warns or raises exception when used N2since must be less or equal to removed, got since= , removed=.cS|SNrrrrrNzdeprecated..Tcstt}|r nj|rdnddjd}r"dd}nr7dd}dur6|dd7}nd }|d |d tfd d }|rX|S|_S) NFunctionZClassz ``was removed in version r)"has been deprecated since version  It will be removed in version has been deprecated. cs*rtrt|i|Sr+)r rargskwargs)call_obj is_deprecated is_removedrrrrr_wrapperjs  z0deprecated.._decorator.._wrapper) isinstancer__init__rstripr)rZis_func msg_prefix msg_infixr<r:r;r!r rr)r9rrr _decoratorYs$  zdeprecated.._decorator)r ValueError)rr r!r#ris_not_yet_deprecatedrCrrBrr )s r namenew_namec s|ds|dstj}dur*dur*ts*tdddduo6|ko6t|}|r=ddSdurJdurJd d nduoRt|duoa|tjkoat|fd d }|S) a Marks a particular named argument of a callable as deprecated. The same conditions for `since` and `removed` as described in the `deprecated` decorator. When the decorated definition is called, that is when the function is called or the class instantiated with args, a `warning_category` is issued if `since` is given and the current version is at or later than that given. a `DeprecatedError` exception is instead raised if `removed` is given and the current version is at or later than that, or if neither `since` nor `removed` is provided. The relevant docstring of the deprecating function should also be updated accordingly, using the Sphinx directives such as `.. versionchanged:: version` and `.. deprecated:: version`. https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-versionadded Args: name: name of position or keyword argument to mark as deprecated. since: version at which the argument was marked deprecated but not removed. removed: version at which the argument was/will be removed and no longer usable. msg_suffix: message appended to warning/exception detailing reasons for deprecation and what to use instead. version_val: (used for testing) version to compare since and removed against, default is MONAI version. new_name: name of position or keyword argument to replace the deprecated argument. if it is specified and the signature of the decorated function has a `kwargs`, the value to the deprecated argument `name` will be removed. warning_category: a warning category class, defaults to `FutureWarning`. Returns: Decorated callable which warns or raises exception when deprecated argument used. 0+rNr'r(r)cSr*r+rr,rrrr-r.z deprecated_arg..Tc sjdjddd}rd d}nr0d d} dur/|d d7}nd }|d|dtt f d d }|S) Nr5: Argument `r0r1r)r2r3r4csdur-|vr-|vr-||<z j|i|jWnty,|dYnwj|i|j}|v}d}jD]\}}|jtjj kr^||vr^||vr^d}|dqA|sc|rqrit rqt |i|S)NFT) bind arguments TypeErrorpop parametersitemskindinspect Parameter VAR_KEYWORDr r)r7r8ZbindingZpositional_foundZkw_foundkparam) argnamefuncr:r;rrFrGsigrrrr<s*  "  z4deprecated_arg.._decorator.._wrapper)rrr?rR signaturer)rXr@rAr<r:r;r!rFrGr rrrWrXrrYrrCs   z"deprecated_arg.._decorator startswithr?isdigitsysmaxsizerrD) rFrr r!r#rGrrErCrr[rr {s&0r old_defaultr new_defaultreplacedc s|ds|dstj}dur*dur*ts*tdddduo6|ko6t|}|r=ddSdurJdurJd d nduoRt|duoa|tjkoat|f d d } | S) a Marks a particular arguments default of a callable as deprecated. It is changed from `old_default` to `new_default` in version `changed`. When the decorated definition is called, a `warning_category` is issued if `since` is given, the default is not explicitly set by the caller and the current version is at or later than that given. Another warning with the same category is issued if `changed` is given and the current version is at or later. The relevant docstring of the deprecating function should also be updated accordingly, using the Sphinx directives such as `.. versionchanged:: version` and `.. deprecated:: version`. https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-versionadded Args: name: name of position or keyword argument where the default is deprecated/changed. old_default: name of the old default. This is only for the warning message, it will not be validated. new_default: name of the new default. It is validated that this value is not present as the default before version `replaced`. This means, that you can also use this if the actual default value is `None` and set later in the function. You can also set this to any string representation, e.g. `"calculate_default_value()"` if the default is calculated from another function. since: version at which the argument default was marked deprecated but not replaced. replaced: version at which the argument default was/will be replaced. msg_suffix: message appended to warning/exception detailing reasons for deprecation. version_val: (used for testing) version to compare since and removed against, default is MONAI version. warning_category: a warning category class, defaults to `FutureWarning`. Returns: Decorated callable which warns when deprecated default argument is not explicitly specified. rHrNz3since must be less or equal to replaced, got since=z , replaced=r)cSr*r+rr,rrrr-r.z(deprecated_arg_default..Tc sbjdjddd d}r*d dd ddd }n*rEd d } durD|d dd d 7}ndd ddd }|d|dtjvrvtddjd j}|jtjj urtdd|jkrstddd d t  fdd}|S)Nr5rIz$ Current default value of argument `=r0zwas changed in version z from `z` to `z`.r2r)z It will be changed to `z ` in version zhas been deprecated from `rJz` not found in signature of z` has no default value.z)` was replaced to the new default value `z` before the specified version cs4j|i|jvrrt|i|Sr+)rKrLrr6)rWrXr:rrFrYrrrr<=s z._decorator.._wrapper) rrr?rRrZrOrDdefaultrSemptyr)rXr@rArVr< r: is_replacedr!rFrcrbrdrrr\rrC!s0&    z*deprecated_arg_default.._decoratorr]) rFrbrcrrdr!r#rrErCrrhrrs)&r) rrr rr!r"r#r"rr$r%r&)rFr"rrr rr!r"r#r"rGrrr$r%r&)rFr"rbrrcrrrrdrr!r"r#r"rr$r%r&) __future__rrRr`rcollections.abcr functoolsrtypesrtypingrrZmonai.utils.modulerrr __all__typer Exceptionr FutureWarningrr r rrrrrsB         T o