Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor is_context_provided #16758

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions python_modules/dagster/dagster/_core/decorator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,9 @@ def is_resource_def(obj: Any) -> TypeGuard["ResourceDefinition"]:
"""
class_names = [cls.__name__ for cls in inspect.getmro(obj.__class__)]
return "ResourceDefinition" in class_names


def is_context_provided(params: Sequence[Parameter]) -> bool:
if len(params) == 0:
return False
return params[0].name in get_valid_name_permutations("context")
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from dagster._config import UserConfigSchema
from dagster._core.decorator_utils import (
format_docstring_for_description,
is_context_provided,
get_function_params,
get_valid_name_permutations,
param_is_var_keyword,
positional_arg_name_list,
)
Expand Down Expand Up @@ -284,6 +284,11 @@ def name(self):
def has_context_arg(self) -> bool:
return is_context_provided(get_function_params(self.decorated_fn))

def get_context_arg(self) -> Parameter:
if self.has_context_arg():
return get_function_params(self.decorated_fn)[0]
check.failed("Requested context arg on function that does not have one")

@lru_cache(maxsize=1)
def _get_function_params(self) -> Sequence[Parameter]:
return get_function_params(self.decorated_fn)
Expand Down Expand Up @@ -337,12 +342,6 @@ def has_context_arg(self) -> bool:
return False


def is_context_provided(params: Sequence[Parameter]) -> bool:
if len(params) == 0:
return False
return params[0].name in get_valid_name_permutations("context")


def resolve_checked_op_fn_inputs(
decorator_name: str,
fn_name: str,
Expand Down