提交 b7ac8a08 authored 作者: Maxim Kochurov's avatar Maxim Kochurov 提交者: Maxim Kochurov

remove deprecation utility, favor pydeprecate (https://pypi.org/project/pyDeprecate/)

上级 225346d7
...@@ -16,6 +16,7 @@ dependencies: ...@@ -16,6 +16,7 @@ dependencies:
- logical-unification - logical-unification
- miniKanren - miniKanren
- cons - cons
- pydeprecate
# Intel BLAS # Intel BLAS
- mkl - mkl
- mkl-service - mkl-service
...@@ -49,3 +50,4 @@ dependencies: ...@@ -49,3 +50,4 @@ dependencies:
# optional # optional
- sympy - sympy
- cython - cython
"""Utility functions that only depend on the standard library.""" """Utility functions that only depend on the standard library."""
import hashlib import hashlib
import inspect
import logging import logging
import os import os
import struct import struct
import subprocess import subprocess
import sys import sys
import traceback
import warnings
from collections import OrderedDict from collections import OrderedDict
from collections.abc import Callable from collections.abc import Callable
from functools import partial, wraps from functools import partial
from typing import List, Set from typing import List, Set
...@@ -19,7 +16,6 @@ __all__ = [ ...@@ -19,7 +16,6 @@ __all__ = [
"get_unbound_function", "get_unbound_function",
"maybe_add_to_os_environ_pathlist", "maybe_add_to_os_environ_pathlist",
"DefaultOrderedDict", "DefaultOrderedDict",
"deprecated",
"subprocess_Popen", "subprocess_Popen",
"call_subprocess_Popen", "call_subprocess_Popen",
"output_subprocess_Popen", "output_subprocess_Popen",
...@@ -140,44 +136,6 @@ def maybe_add_to_os_environ_pathlist(var, newpath): ...@@ -140,44 +136,6 @@ def maybe_add_to_os_environ_pathlist(var, newpath):
pass pass
def deprecated(message: str = ""):
"""
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 first time and filter is set for show DeprecationWarning.
Taken from https://stackoverflow.com/a/40899499/4473230
"""
def decorator_wrapper(func):
@wraps(func)
def function_wrapper(*args, **kwargs):
nonlocal message
current_call_source = "|".join(
traceback.format_stack(inspect.currentframe())
)
if current_call_source not in function_wrapper.last_call_source:
if not message:
message = f"Function {func.__name__} is deprecated."
warnings.warn(
message,
category=DeprecationWarning,
stacklevel=2,
)
function_wrapper.last_call_source.add(current_call_source)
return func(*args, **kwargs)
function_wrapper.last_call_source = set()
return function_wrapper
return decorator_wrapper
def subprocess_Popen(command, **params): def subprocess_Popen(command, **params):
""" """
Utility function to work around windows behavior that open windows. Utility function to work around windows behavior that open windows.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论