[BE] wrap deprecated function/class with typing_extensions.deprecated (#126898)

Use `typing_extensions.deprecated` for deprecation annotation if possible. Otherwise, add `category=FutureWarning` to `warnings.warn("message")` if the category is missing.

Note that only warnings that their messages contain `[Dd]eprecat(ed|ion)` are updated in this PR.

UPDATE: Use `FutureWarning` instead of `DeprecationWarning`.

Resolves #126888

- #126888

Pull Request resolved: https://github.com/pytorch/pytorch/pull/126898
Approved by: https://github.com/albanD
This commit is contained in:
Xuehai Pan
2024-05-29 12:09:24 +00:00
committed by PyTorch MergeBot
parent 699db7988d
commit 749a132fb0
117 changed files with 700 additions and 478 deletions

View File

@ -13,6 +13,7 @@ import warnings
import zipfile
from pathlib import Path
from typing import Dict, Optional, Any
from typing_extensions import deprecated
from urllib.error import HTTPError, URLError
from urllib.request import urlopen, Request
from urllib.parse import urlparse # noqa: F401
@ -680,10 +681,13 @@ def _is_legacy_zip_format(filename: str) -> bool:
return False
@deprecated(
'Falling back to the old format < 1.6. This support will be '
'deprecated in favor of default zipfile format introduced in 1.6. '
'Please redo torch.save() to save it in the new zipfile format.',
category=FutureWarning,
)
def _legacy_zip_load(filename: str, model_dir: str, map_location: MAP_LOCATION, weights_only: bool) -> Dict[str, Any]:
warnings.warn('Falling back to the old format < 1.6. This support will be '
'deprecated in favor of default zipfile format introduced in 1.6. '
'Please redo torch.save() to save it in the new zipfile format.')
# Note: extractall() defaults to overwrite file if exists. No need to clean up beforehand.
# We deliberately don't handle tarfile here since our legacy serialization format was in tar.
# E.g. resnet18-5c106cde.pth which is widely used.