def __new__( cls, asset_key, description=None, metadata_entries=None, partition=None, tags=None, metadata=None, ): if isinstance(asset_key, AssetKey): check.inst_param(asset_key, "asset_key", AssetKey) elif isinstance(asset_key, str): asset_key = AssetKey(parse_asset_key_string(asset_key)) elif isinstance(asset_key, list): check.is_list(asset_key, of_type=str) asset_key = AssetKey(asset_key) else: check.is_tuple(asset_key, of_type=str) asset_key = AssetKey(asset_key) if tags: experimental_class_param_warning("tags", "AssetMaterialization") return super(AssetMaterialization, cls).__new__( cls, asset_key=asset_key, description=check.opt_str_param(description, "description"), metadata_entries=parse_metadata(metadata, metadata_entries), partition=check.opt_str_param(partition, "partition"), tags=check.opt_dict_param(tags, "tags", key_type=str, value_type=str), )
def __new__(cls, asset_key, description=None, metadata_entries=None, partition=None): if isinstance(asset_key, AssetKey): check.inst_param(asset_key, "asset_key", AssetKey) elif isinstance(asset_key, str): asset_key = AssetKey(parse_asset_key_string(asset_key)) elif isinstance(asset_key, list): check.is_list(asset_key, of_type=str) asset_key = AssetKey(asset_key) else: check.is_tuple(asset_key, of_type=str) asset_key = AssetKey(asset_key) return super(AssetMaterialization, cls).__new__( cls, asset_key=asset_key, description=check.opt_str_param(description, "description"), metadata_entries=check.opt_list_param(metadata_entries, metadata_entries, of_type=EventMetadataEntry), partition=check.opt_str_param(partition, "partition"), )
def __new__( cls, asset_key: Union[List[str], AssetKey, str], description: Optional[str] = None, metadata_entries: Optional[List[EventMetadataEntry]] = None, partition: Optional[str] = None, metadata: Optional[Dict[str, ParseableMetadataEntryData]] = None, ): if isinstance(asset_key, AssetKey): check.inst_param(asset_key, "asset_key", AssetKey) elif isinstance(asset_key, str): asset_key = AssetKey(parse_asset_key_string(asset_key)) elif isinstance(asset_key, list): check.is_list(asset_key, of_type=str) asset_key = AssetKey(asset_key) else: check.is_tuple(asset_key, of_type=str) asset_key = AssetKey(asset_key) metadata = check.opt_dict_param(metadata, "metadata", key_type=str) metadata_entries = check.opt_list_param(metadata_entries, "metadata_entries", of_type=EventMetadataEntry) return super(AssetObservation, cls).__new__( cls, asset_key=asset_key, description=check.opt_str_param(description, "description"), metadata_entries=cast(List[EventMetadataEntry], parse_metadata(metadata, metadata_entries)), partition=check.opt_str_param(partition, "partition"), )
def merge_dicts(*args) -> dict: check.is_tuple(args, of_type=dict) if len(args) < 2: check.failed( f"Expected 2 or more args to merge_dicts, found {len(args)}") result = args[0].copy() for arg in args[1:]: result.update(arg) return result
def merge_dicts(*args: Mapping) -> dict: """ Returns a dictionary with with all the keys in all of the input dictionaries. If multiple input dictionaries have different values for the same key, the returned dictionary contains the value from the dictionary that comes latest in the list. """ check.is_tuple(args, of_type=dict) if len(args) < 2: check.failed( f"Expected 2 or more args to merge_dicts, found {len(args)}") result: dict = {} for arg in args: result.update(arg) return result
def __new__(cls, asset_key, description=None, metadata_entries=None, dagster_type=None): if isinstance(asset_key, AssetKey): check.inst_param(asset_key, 'asset_key', AssetKey) elif check.is_str(asset_key): asset_key = AssetKey(parse_asset_key_string(asset_key)) elif isinstance(asset_key, list): check.is_list(asset_key, of_type=str) asset_key = AssetKey(asset_key) else: check.is_tuple(asset_key, of_type=str) asset_key = AssetKey(asset_key) if dagster_type is not None: from dagster.core.types.dagster_type import DagsterType # importing here to resolve circularity dagster_type = check.inst_param(dagster_type, 'dagster_type', DagsterType) metadata_entries = check.opt_list_param(metadata_entries, metadata_entries, of_type=EventMetadataEntry) if metadata_entries is None: metadata_entries = [] metadata_entries.append( EventMetadataEntry.text( (dagster_type.name if dagster_type.name else 'Any'), 'system-type-name')) metadata_entries.append( EventMetadataEntry.text( (dagster_type.description if dagster_type.description else 'Any'), 'system-type-description', )) return super(AssetMaterialization, cls).__new__( cls, asset_key=asset_key, description=check.opt_str_param(description, 'description'), metadata_entries=check.opt_list_param(metadata_entries, metadata_entries, of_type=EventMetadataEntry), )
def test_non_variadic_union_type_is_tuple(): class Foo: pass class Bar: pass # this is the behavior of isinstance foo_tuple = (Foo(), ) for item in foo_tuple: assert isinstance(item, (Foo, Bar)) # This call fails: # This does not call isinstance on tuple member and instead does # non-variadic typing. It is impossible to check that each # member is Foo or Bar given current API design check.is_tuple(foo_tuple, of_type=(Foo, Bar))
def test_tuple_param(): assert check.tuple_param((1, 2), "something") with pytest.raises(CheckError): assert check.tuple_param(None, "something") with pytest.raises(CheckError): assert check.tuple_param(1, "something") with pytest.raises(CheckError): assert check.tuple_param([1], "something") with pytest.raises(CheckError): assert check.tuple_param({1: 2}, "something") with pytest.raises(CheckError): assert check.tuple_param("kdjfkd", "something") assert check.tuple_param((3, 4), "something", of_type=int) assert check.tuple_param(("foo", "bar"), "something", of_type=str) assert check.tuple_param((3, 4), "something", of_type=(int, )) assert check.tuple_param((3, 4), "something", of_type=(int, str)) assert check.tuple_param((3, "bar"), "something", of_type=(int, str)) with pytest.raises(CheckError): check.tuple_param((3, 4, 5), "something", of_type=str) with pytest.raises(CheckError): check.tuple_param((3, 4), "something", of_type=(str, )) assert check.tuple_param((3, "a"), "something", of_shape=(int, str)) with pytest.raises(CheckError): check.tuple_param((3, "a"), "something", of_shape=(int, str, int)) with pytest.raises(CheckError): check.tuple_param((3, "a"), "something", of_shape=(str, int)) with pytest.raises(CheckError): check.is_tuple((3, 4), of_shape=(int, int), of_type=int)
def __new__( cls, asset_key: Union[List[str], AssetKey, str], description: Optional[str] = None, metadata_entries: Optional[List[EventMetadataEntry]] = None, partition: Optional[str] = None, tags: Optional[Dict[str, str]] = None, metadata: Optional[Dict[str, MetadataValues]] = None, ): if isinstance(asset_key, AssetKey): check.inst_param(asset_key, "asset_key", AssetKey) elif isinstance(asset_key, str): asset_key = AssetKey(parse_asset_key_string(asset_key)) elif isinstance(asset_key, list): check.is_list(asset_key, of_type=str) asset_key = AssetKey(asset_key) else: check.is_tuple(asset_key, of_type=str) asset_key = AssetKey(asset_key) if tags: experimental_class_param_warning("tags", "AssetMaterialization") metadata = check.opt_dict_param(metadata, "metadata", key_type=str) metadata_entries = check.opt_list_param(metadata_entries, "metadata_entries", of_type=EventMetadataEntry) return super(AssetMaterialization, cls).__new__( cls, asset_key=asset_key, description=check.opt_str_param(description, "description"), metadata_entries=cast(List[EventMetadataEntry], parse_metadata(metadata, metadata_entries)), partition=check.opt_str_param(partition, "partition"), tags=check.opt_dict_param(tags, "tags", key_type=str, value_type=str), )
def test_is_tuple(): assert check.is_tuple(()) == () with pytest.raises(CheckError): check.is_tuple(None) with pytest.raises(CheckError): check.is_tuple("3u4") with pytest.raises(CheckError, match="Did you pass a class"): check.is_tuple((str, ), of_type=int)
def test_typed_is_tuple(): class Foo(object): pass class Bar(object): pass assert check.is_tuple((), Foo) == () foo_tuple = (Foo(), ) assert check.is_tuple(foo_tuple, Foo) == foo_tuple with pytest.raises(CheckError): check.is_tuple((Bar(), ), Foo) with pytest.raises(CheckError): check.is_tuple((None, ), Foo)
def test_typed_is_tuple(): class Foo: pass class Bar: pass assert check.is_tuple((), Foo) == () foo_tuple = (Foo(), ) assert check.is_tuple(foo_tuple, Foo) == foo_tuple assert check.is_tuple(foo_tuple, (Foo, Bar)) with pytest.raises(CheckError): check.is_tuple((Bar(), ), Foo) with pytest.raises(CheckError): check.is_tuple((None, ), Foo) assert check.is_tuple((Foo(), Bar()), of_shape=(Foo, Bar)) with pytest.raises(CheckError): check.is_tuple((Foo(), ), of_shape=(Foo, Bar)) with pytest.raises(CheckError): check.is_tuple((Foo(), Foo()), of_shape=(Foo, Bar)) with pytest.raises(CheckError): check.is_tuple((Foo(), Foo()), of_shape=(Foo, Foo), of_type=Foo)