Skip to content

Commit

Permalink
chore: deprecated周りを変更
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Nov 27, 2022
1 parent 05ac3c6 commit 177f234
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mipac/models/lite/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
29 changes: 20 additions & 9 deletions mipac/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,8 +24,7 @@
HAS_ORJSON = True

__all__ = (
'deprecated_property',
'deprecated_func',
'deprecated',
'MiTime',
'get_cache_key',
'key_builder',
Expand All @@ -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:
Expand Down

0 comments on commit 177f234

Please sign in to comment.