feat: add local deprecation descriptor (in reserve; not used) (#28695)
* feat: add local deprecation descriptor (in reserve; not used)
This commit is contained in:
parent
fef569e284
commit
c8a972a039
1 changed files with 39 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ import inspect
|
|||
import os
|
||||
import re
|
||||
import sys
|
||||
import typing
|
||||
import warnings
|
||||
from importlib.metadata import version
|
||||
|
||||
|
|
@ -200,6 +201,44 @@ def deprecation_warning(marked: str, graduation: str, msg: str):
|
|||
|
||||
|
||||
### Party starts here
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from werkzeug.local import Local
|
||||
|
||||
|
||||
def get_local_with_deprecations() -> "Local":
|
||||
from werkzeug.local import Local
|
||||
|
||||
class DeprecatedLocalAttribute:
|
||||
def __init__(self, name, warning):
|
||||
self.name = name
|
||||
self.warning = warning
|
||||
|
||||
def __get__(self, obj, type=None):
|
||||
self.warning()
|
||||
return obj.__getattr__(self.name)
|
||||
|
||||
def __set__(self, obj, value):
|
||||
return obj.__setattr__(self.name, value)
|
||||
|
||||
def __delete__(self, obj):
|
||||
return obj.__delattr__(self.name)
|
||||
|
||||
class LocalWithDeprecations(Local):
|
||||
"""Can deprecate local attributes."""
|
||||
|
||||
# sites_path = DeprecatedLocalAttribute(
|
||||
# "sites_path",
|
||||
# lambda: deprecation_warning(
|
||||
# "2024-12-06",
|
||||
# "v17",
|
||||
# "'local.sites_path' will be deprecated: use 'frappe.bench.sites.path instead'",
|
||||
# ),
|
||||
# )
|
||||
|
||||
return LocalWithDeprecations()
|
||||
|
||||
|
||||
def _old_deprecated(func):
|
||||
return deprecated(
|
||||
"frappe.deprecations.deprecated",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue