From 177f234d173832e88a8d676791fadc43e65a540b Mon Sep 17 00:00:00 2001 From: yupix Date: Sun, 27 Nov 2022 12:08:09 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20deprecated=E5=91=A8=E3=82=8A=E3=82=92?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ mipac/models/lite/user.py | 2 +- mipac/util.py | 29 ++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 437eb66d..e12229e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - `LiteUser` に属性 `name` を互換性の為に再追加しましたが、非推奨です。v0.4.0で削除する予定です - `username` と `name` の違いを区別しにくい可能性がある為、新たに使用する際は `nickname` を使用することを推奨しています + +### Removed + +- `deprecated_property` decorator を削除しました +- `deprecated_func` decorator を削除しました + ## [0.2.1] - 2022-11-27 ### Added diff --git a/mipac/models/lite/user.py b/mipac/models/lite/user.py index 071c6830..ce51c60e 100644 --- a/mipac/models/lite/user.py +++ b/mipac/models/lite/user.py @@ -24,8 +24,8 @@ def username(self) -> str: def host(self) -> str | None: return self.__user['host'] - @deprecated_property @property + @deprecated def name(self) -> str: return self.__user['name'] diff --git a/mipac/util.py b/mipac/util.py index f4e1a15e..85c6057c 100644 --- a/mipac/util.py +++ b/mipac/util.py @@ -11,6 +11,7 @@ from datetime import datetime, timedelta from typing import Any, Optional from urllib.parse import urlencode +import warnings import aiohttp from _operator import itemgetter @@ -23,8 +24,7 @@ HAS_ORJSON = True __all__ = ( - 'deprecated_property', - 'deprecated_func', + 'deprecated', 'MiTime', 'get_cache_key', 'key_builder', @@ -46,14 +46,25 @@ DEFAULT_CACHE: dict[str, list[dict[str, Any]]] = {} -def deprecated_property(func: property) -> None: - _func = func.fget or func.fdel or func.fset - if _func: - print(f'deprecated property: {_func.__name__}') - +def deprecated(func): + """ + This is a decorator which can be used to mark functions + as deprecated. It will result in a warning being emitted + when the function is used. + """ + + @functools.wraps(func) + def new_func(*args, **kwargs): + warnings.simplefilter('always', DeprecationWarning) # turn off filter + warnings.warn( + 'Call to deprecated function {}.'.format(func.__name__), + category=DeprecationWarning, + stacklevel=2, + ) + warnings.simplefilter('default', DeprecationWarning) # reset filter + return func(*args, **kwargs) -def deprecated_func(func) -> None: - print(f'deprecated function:{func.__name__}') + return new_func class MiTime: