Skip to content

Commit

Permalink
metaclass
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiedemaria committed Sep 18, 2023
1 parent 59fd5df commit 9e2cf21
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions python_modules/dagster/dagster/_core/execution/context/compute.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from abc import ABC, abstractmethod
from abc import ABC, ABCMeta, abstractmethod
from typing import (
AbstractSet,
Any,
Expand Down Expand Up @@ -50,7 +50,12 @@
from .system import StepExecutionContext


class AbstractComputeExecutionContext(ABC):
# This metaclass has to exist for OpExecutionContext to have a metaclass
class AbstractComputeMetaclass(ABCMeta):
pass


class AbstractComputeExecutionContext(ABC, metaclass=AbstractComputeMetaclass):
"""Base class for op context implemented by OpExecutionContext and DagstermillExecutionContext."""

@abstractmethod
Expand Down Expand Up @@ -97,7 +102,18 @@ def op_config(self) -> Any:
"""The parsed config specific to this op."""


class OpExecutionContext(AbstractComputeExecutionContext):
class OpExecutionContextMetaClass(AbstractComputeMetaclass):
def __instancecheck__(cls, instance) -> bool:
# This makes isinstance(context, OpExecutionContext) return True when
# the context is an AssetExecutionContext. This makes the new
# AssetExecutionContext backwards compatible with the old
# OpExecutionContext codepaths.
if isinstance(instance, AssetExecutionContext):
return True
return super().__instancecheck__(instance)


class OpExecutionContext(AbstractComputeExecutionContext, metaclass=OpExecutionContextMetaClass):
"""The ``context`` object that can be made available as the first argument to the function
used for computing an op or asset.
Expand Down

0 comments on commit 9e2cf21

Please sign in to comment.