|
1 | | -import warnings |
2 | | -from enum import Enum, EnumMeta, Flag, IntFlag, unique |
3 | | -from typing import Any, Callable, Iterable, Type, TypeVar, Union |
| 1 | +from enum import Enum, Flag, IntFlag, unique |
| 2 | +from typing import Callable, Type, TypeVar, Union |
4 | 3 |
|
5 | | -from databento.live.dbn import DBNRecord |
6 | 4 | from databento_dbn import ( |
7 | 5 | ImbalanceMsg, |
8 | 6 | InstrumentDefMsg, |
|
14 | 12 | TradeMsg, |
15 | 13 | ) |
16 | 14 |
|
| 15 | +from databento.live.dbn import DBNRecord |
17 | 16 |
|
18 | 17 | M = TypeVar("M", bound=Enum) |
19 | 18 |
|
@@ -90,46 +89,6 @@ def coerced_new(enum: Type[M], value: object) -> M: |
90 | 89 | return enum_type |
91 | 90 |
|
92 | 91 |
|
93 | | -class DeprecatedAccess(EnumMeta): |
94 | | - """ |
95 | | - runs a user-specified function whenever member is accessed |
96 | | - """ |
97 | | - |
98 | | - def __getattribute__(cls, name: str) -> object: |
99 | | - obj = super().__getattribute__(name) |
100 | | - if isinstance(obj, Enum) and obj._on_access: # type: ignore |
101 | | - obj._on_access() # type: ignore |
102 | | - return obj |
103 | | - |
104 | | - def __getitem__(cls, name: str, *_: Iterable[Any]) -> object: # type: ignore |
105 | | - member: Any = super().__getitem__(name) |
106 | | - if member._on_access: |
107 | | - member._on_access() |
108 | | - return member |
109 | | - |
110 | | - def __call__( # type: ignore |
111 | | - cls, |
112 | | - value: str, |
113 | | - names=None, |
114 | | - *, |
115 | | - module=None, |
116 | | - qualname=None, |
117 | | - type=None, |
118 | | - start=1, |
119 | | - ) -> object: |
120 | | - obj = super().__call__( |
121 | | - value, |
122 | | - names, |
123 | | - module=module, |
124 | | - qualname=qualname, |
125 | | - type=type, |
126 | | - start=start, |
127 | | - ) |
128 | | - if isinstance(obj, Enum) and obj._on_access: |
129 | | - obj._on_access() |
130 | | - return obj |
131 | | - |
132 | | - |
133 | 92 | class StringyMixin: |
134 | 93 | """ |
135 | 94 | Mixin class for overloading __str__ on Enum types. |
@@ -273,46 +232,16 @@ class Delivery(StringyMixin, str, Enum): |
273 | 232 | DISK = "disk" |
274 | 233 |
|
275 | 234 |
|
276 | | -def deprecated_enum(old_value: str, new_value: str) -> str: |
277 | | - warnings.warn( |
278 | | - f"{old_value} is deprecated to {new_value}", |
279 | | - category=DeprecationWarning, |
280 | | - stacklevel=3, # This makes the error happen in user code |
281 | | - ) |
282 | | - return new_value |
283 | | - |
284 | | - |
285 | 235 | @unique |
286 | 236 | @coercible |
287 | | -class SType(StringyMixin, str, Enum, metaclass=DeprecatedAccess): |
| 237 | +class SType(StringyMixin, str, Enum): |
288 | 238 | """Represents a symbology type.""" |
289 | 239 |
|
290 | | - PRODUCT_ID = "product_id", "instrument_id" # Deprecated for `instrument_id` |
291 | | - NATIVE = "native", "raw_symbol" # Deprecated for `raw_symbol` |
292 | | - SMART = "smart", "parent", "continuous" # Deprecated for `parent` and `continuous` |
293 | 240 | INSTRUMENT_ID = "instrument_id" |
294 | 241 | RAW_SYMBOL = "raw_symbol" |
295 | 242 | PARENT = "parent" |
296 | 243 | CONTINUOUS = "continuous" |
297 | 244 |
|
298 | | - def __new__(cls, value: str, *args: Iterable[str]) -> "SType": |
299 | | - variant = super().__new__(cls, value) |
300 | | - variant._value_ = value |
301 | | - variant.__args = args # type: ignore |
302 | | - variant._on_access = variant.__deprecated if args else None # type: ignore |
303 | | - return variant |
304 | | - |
305 | | - def __eq__(self, other: object) -> bool: |
306 | | - return str(self).lower() == str(other).lower() |
307 | | - |
308 | | - def __deprecated(self) -> None: |
309 | | - other_values = " or ".join(self.__args) # type: ignore |
310 | | - warnings.warn( |
311 | | - f"SType of {self.value} is deprecated; use {other_values}", |
312 | | - category=DeprecationWarning, |
313 | | - stacklevel=3, |
314 | | - ) |
315 | | - |
316 | 245 |
|
317 | 246 | @unique |
318 | 247 | @coercible |
|
0 commit comments