U Ph9 @s ddlmZddlZddlZddlZddlmZddlmZddl m Z ddl m Z m Z ddlmZdd lmZd d d d gZe deeZGdd d eZefddZdddeefddddddddd Zdddedefddddddddddd Zdddeefdddddddddd dd ZdS)) annotationsN)Callable)wraps) FunctionType)AnyTypeVar) version_leq) __version__ deprecateddeprecated_argDeprecatedErrordeprecated_arg_defaultTc@s eZdZdS)r N)__name__ __module__ __qualname__rrP/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/utils/deprecate_utils.pyr scCstj|d||dddS)z* Issue the warning message `msg`. z: r )category stacklevelN)warningswarn)objmsgwarning_categoryrrrwarn_deprecated"srz str | Nonestrztype[FutureWarning]zCallable[[T], T])sinceremoved msg_suffix version_valrreturncsdk r0dk r0ts0tddddk oH|koHt|}|rVddSdkrpdkrpddn$dk ot|dk ot|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=.cSs|SNrrrrrNzdeprecated..Tcstt}|rnj|r dnddjd}rDdd}n.rndd}dk rr|dd7}nd }|d |d tfd d }|r|S|_S) NFunctionZClassz ``was removed in version r&"has been deprecated since version  It will be removed in version has been deprecated. cs&r trt||Sr')r rargskwargs)call_obj is_deprecated is_removedrrrrr_wrapperjs  z0deprecated.._decorator.._wrapper) isinstancer__init__rstripr)ris_func msg_prefix msg_infixr8r6r7r!r rr)r5rrr _decoratorYs"  zdeprecated.._decorator)r ValueError)rr r!r"ris_not_yet_deprecatedr@rr?rr )s )namerr r!r"new_namerr#c s|ds|ds$tj}dk rTdk rTtsTtddddk ol|kolt|}|rzddSdkrdkrd d n0dk ot|dk o|tjkot|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&cSs|Sr'rr(rrrr)r*z deprecated_arg..Tc sjdjddd}r6d d}n.r`d d} dk rd|d d7}nd }|d|dtt f d d }|S) Nr1: Argument `r,r-r&r.r/r0csdk rX|krX|krX||<zj||jWn tk rV|dYnXj||j}|k}d}jD]:\}}|jtjj kr|||kr|||kr|d}|dq||s|r܈rt rt ||S)NFT) bind arguments TypeErrorpop parametersitemskindinspect Parameter VAR_KEYWORDr r)r3r4bindingZpositional_foundZkw_foundkparam) argnamefuncr6r7rrCrDsigrrrr8s& " z4deprecated_arg.._decorator.._wrapper)rrr;rO signaturer)rVr=r>r8r6r7r!rCrDr rrrUrVrrWrr@s   z"deprecated_arg.._decorator startswithr;isdigitsysmaxsizerrA) rCrr r!r"rDrrBr@rrYrr {s&0r) rC old_default new_defaultrreplacedr!r"rr#c s|ds|ds$tj}dk rTdk rTtsTtddddk ol|kolt|}|rzddSdkrdkrd d n0dk ot|dk o|tjkot|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. rErNz3since must be less or equal to replaced, got since=z , replaced=r&cSs|Sr'rr(rrrr)r*z(deprecated_arg_default..Tc shjdjddd d}rTd dd ddd }nTrd d } dk r|d dd d 7}ndd ddd }|d|dtjkrtddjd j}|jtjj krtdd|jkrDsDtddd d t  fdd}|S)Nr1rFz$ Current default value of argument `=r,zwas changed in version z from `z` to `z`.r.r&z It will be changed to `z ` in version zhas been deprecated from `rGz` not found in signature of z` has no default value.z)` was replaced to the new default value `z` before the specified version cs,j||jkr"r"t||Sr')rHrIrr2)rUrVr6rrCrWrrrr8=s z._decorator.._wrapper) rrr;rOrXrLrAdefaultrPemptyr)rVr=r>rTr8 r6Z is_replacedr!rCrar`rbrrrZrr@!s.&    z*deprecated_arg_default.._decoratorr[) rCr`rarrbr!r"rrBr@rrfrrs)&) __future__rrOr^rcollections.abcr functoolsrtypesrtypingrrZmonai.utils.modulerrr __all__typer Exceptionr FutureWarningrr r rrrrr s@         To