Changeset View
Changeset View
Standalone View
Standalone View
python_modules/dagster/dagster/utils/backcompat.py
Show First 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | def experimental_functionality_warning(desc, stacklevel=3): | ||||
warnings.warn( | warnings.warn( | ||||
f"{desc} is currently experimental functionality. It may break in future versions, even " | f"{desc} is currently experimental functionality. It may break in future versions, even " | ||||
f"between dot releases. {EXPERIMENTAL_WARNING_HELP}", | f"between dot releases. {EXPERIMENTAL_WARNING_HELP}", | ||||
ExperimentalWarning, | ExperimentalWarning, | ||||
stacklevel=stacklevel, | stacklevel=stacklevel, | ||||
) | ) | ||||
def experimental(fn): | def experimental_fn(fn): | ||||
""" | """ | ||||
Spews an "experimental" warning whenever the given callable is called. If the argument is a | Spews an "experimental" warning whenever the given callable is called. | ||||
class, this means the warning will be emitted when the class is instantiated. | |||||
Usage: | Usage: | ||||
.. code-block:: python | .. code-block:: python | ||||
@experimental | @experimental | ||||
def my_experimental_function(my_arg): | def my_experimental_function(my_arg): | ||||
do_stuff() | do_stuff() | ||||
""" | """ | ||||
check.callable_param(fn, "fn") | check.callable_param(fn, "fn") | ||||
@wraps(fn) | @wraps(fn) | ||||
def _inner(*args, **kwargs): | def _inner(*args, **kwargs): | ||||
experimental_fn_warning(fn.__name__, stacklevel=3) | experimental_fn_warning(fn.__name__, stacklevel=3) | ||||
return fn(*args, **kwargs) | return fn(*args, **kwargs) | ||||
return _inner | return _inner | ||||
def experimental_class(cls): | |||||
""" | |||||
Spews an "experimental" warning whenever the given class is instantiated. | |||||
Usage: | |||||
.. code-block:: python | |||||
@experimental | |||||
class MyExperimentalClass: | |||||
pass | |||||
""" | |||||
check.inst_param(cls, "cls", type) | |||||
prha: generally prefer not to use `old`/`new` in var names.
how about `old` => `dunder_init` and… | |||||
dunder_init = cls.__init__ | |||||
def warn_and_init(self, *args, **kwargs): | |||||
experimental_class_warning(cls.__name__) | |||||
dunder_init(self, *args, **kwargs) | |||||
Not Done Inline Actionsfeel a little leery of doing this assignment, but I can't identify any glaring gotchas... @alangenfeld / @max any thoughts? prha: feel a little leery of doing this assignment, but I can't identify any glaring gotchas... | |||||
Done Inline ActionsYeah definitely felt this was a bit weird but couldn't get subclassing to work without also overriding important metadata about the class (e.g. __name__, etc.) sidkmenon: Yeah definitely felt this was a bit weird but couldn't get subclassing to work without also… | |||||
cls.__init__ = warn_and_init | |||||
return cls | |||||
def experimental(callable_obj): | |||||
""" | |||||
Spews an "experimental" warning whenever the given callable is called. If the argument is a | |||||
class, this means the warning will be emitted when the class is instantiated. | |||||
Usage: | |||||
.. code-block:: python | |||||
@experimental | |||||
def my_experimental_function(my_arg): | |||||
do_stuff() | |||||
@experimental | |||||
class MyExperimentalClass: | |||||
pass | |||||
""" | |||||
if isinstance(callable_obj, type): | |||||
return experimental_class(callable_obj) | |||||
else: | |||||
return experimental_fn(callable_obj) |
generally prefer not to use old/new in var names.
how about old => dunder_init and new => warn_and_init?