forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "[ONNX] Adjust and add deprecation messages (pytorch#146639)"
This reverts commit 63c2909. Reverted pytorch#146639 on behalf of https://github.com/atalman due to Sorry Need to revert pytorch#146425 ([comment](pytorch#146639 (comment)))
- Loading branch information
1 parent
a36c22f
commit 1557b7b
Showing
7 changed files
with
151 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"""Utility for deprecating functions.""" | ||
|
||
import functools | ||
import textwrap | ||
import warnings | ||
from typing import Callable, TypeVar | ||
from typing_extensions import ParamSpec | ||
|
||
|
||
_T = TypeVar("_T") | ||
_P = ParamSpec("_P") | ||
|
||
|
||
def deprecated( | ||
since: str, removed_in: str, instructions: str | ||
) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]: | ||
"""Marks functions as deprecated. | ||
It will result in a warning when the function is called and a note in the | ||
docstring. | ||
Args: | ||
since: The version when the function was first deprecated. | ||
removed_in: The version when the function will be removed. | ||
instructions: The action users should take. | ||
""" | ||
|
||
def decorator(function: Callable[_P, _T]) -> Callable[_P, _T]: | ||
@functools.wraps(function) | ||
def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _T: | ||
warnings.warn( | ||
f"'{function.__module__}.{function.__name__}' " | ||
f"is deprecated in version {since} and will be " | ||
f"removed in {removed_in}. Please {instructions}.", | ||
category=DeprecationWarning, | ||
stacklevel=2, | ||
) | ||
return function(*args, **kwargs) | ||
|
||
# Add a deprecation note to the docstring. | ||
docstring = function.__doc__ or "" | ||
|
||
# Add a note to the docstring. | ||
deprecation_note = textwrap.dedent( | ||
f"""\ | ||
.. deprecated:: {since} | ||
Deprecated and will be removed in version {removed_in}. | ||
Please {instructions}. | ||
""" | ||
) | ||
|
||
# Split docstring at first occurrence of newline | ||
summary_and_body = docstring.split("\n\n", 1) | ||
|
||
if len(summary_and_body) > 1: | ||
summary, body = summary_and_body | ||
|
||
# Dedent the body. We cannot do this with the presence of the summary because | ||
# the body contains leading whitespaces when the summary does not. | ||
body = textwrap.dedent(body) | ||
|
||
new_docstring_parts = [deprecation_note, "\n\n", summary, body] | ||
else: | ||
summary = summary_and_body[0] | ||
|
||
new_docstring_parts = [deprecation_note, "\n\n", summary] | ||
|
||
wrapper.__doc__ = "".join(new_docstring_parts) | ||
|
||
return wrapper | ||
|
||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from __future__ import annotations | ||
|
||
|
||
class ExportTypes: | ||
"""Specifies how the ONNX model is stored.""" | ||
|
||
# TODO(justinchuby): Deprecate and remove this class. | ||
|
||
PROTOBUF_FILE = "Saves model in the specified protobuf file." | ||
ZIP_ARCHIVE = "Saves model in the specified ZIP file (uncompressed)." | ||
COMPRESSED_ZIP_ARCHIVE = "Saves model in the specified ZIP file (compressed)." | ||
DIRECTORY = "Saves model in the specified folder." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.