|
1 | 1 | """Utility functions that only depend on the standard library.""" |
2 | 2 |
|
3 | 3 | import hashlib |
4 | | -import inspect |
5 | 4 | import logging |
6 | 5 | import os |
7 | 6 | import struct |
8 | 7 | import subprocess |
9 | 8 | import sys |
10 | | -import traceback |
11 | | -import warnings |
12 | 9 | from collections import OrderedDict |
13 | 10 | from collections.abc import Callable |
14 | | -from functools import partial, wraps |
| 11 | +from functools import partial |
15 | 12 | from typing import List, Set |
16 | 13 |
|
17 | 14 |
|
18 | 15 | __all__ = [ |
19 | 16 | "get_unbound_function", |
20 | 17 | "maybe_add_to_os_environ_pathlist", |
21 | 18 | "DefaultOrderedDict", |
22 | | - "deprecated", |
23 | 19 | "subprocess_Popen", |
24 | 20 | "call_subprocess_Popen", |
25 | 21 | "output_subprocess_Popen", |
@@ -140,44 +136,6 @@ def maybe_add_to_os_environ_pathlist(var, newpath): |
140 | 136 | pass |
141 | 137 |
|
142 | 138 |
|
143 | | -def deprecated(message: str = ""): |
144 | | - """ |
145 | | - This is a decorator which can be used to mark functions |
146 | | - as deprecated. It will result in a warning being emitted |
147 | | - when the function is used first time and filter is set for show DeprecationWarning. |
148 | | -
|
149 | | - Taken from https://stackoverflow.com/a/40899499/4473230 |
150 | | - """ |
151 | | - |
152 | | - def decorator_wrapper(func): |
153 | | - @wraps(func) |
154 | | - def function_wrapper(*args, **kwargs): |
155 | | - nonlocal message |
156 | | - |
157 | | - current_call_source = "|".join( |
158 | | - traceback.format_stack(inspect.currentframe()) |
159 | | - ) |
160 | | - if current_call_source not in function_wrapper.last_call_source: |
161 | | - |
162 | | - if not message: |
163 | | - message = f"Function {func.__name__} is deprecated." |
164 | | - |
165 | | - warnings.warn( |
166 | | - message, |
167 | | - category=DeprecationWarning, |
168 | | - stacklevel=2, |
169 | | - ) |
170 | | - function_wrapper.last_call_source.add(current_call_source) |
171 | | - |
172 | | - return func(*args, **kwargs) |
173 | | - |
174 | | - function_wrapper.last_call_source = set() |
175 | | - |
176 | | - return function_wrapper |
177 | | - |
178 | | - return decorator_wrapper |
179 | | - |
180 | | - |
181 | 139 | def subprocess_Popen(command, **params): |
182 | 140 | """ |
183 | 141 | Utility function to work around windows behavior that open windows. |
|
0 commit comments