uranusjr commented on code in PR #44639: URL: https://github.com/apache/airflow/pull/44639#discussion_r1876732671
########## task_sdk/src/airflow/sdk/definitions/asset/__init__.py: ########## @@ -54,9 +55,26 @@ class AssetUniqueKey(NamedTuple): uri: str @staticmethod - def from_asset(asset: Asset) -> AssetUniqueKey: + def from_asset(asset: Asset | AssetModel) -> AssetUniqueKey: return AssetUniqueKey(name=asset.name, uri=asset.uri) + def to_asset(self) -> Asset: + return Asset(name=self.name, uri=self.uri) + + +class AssetAliasUniqueKey(NamedTuple): + name: str + + @staticmethod + def from_asset_alias(asset_alias: AssetAlias) -> AssetAliasUniqueKey: + return AssetAliasUniqueKey(name=asset_alias.name) + + def to_asset_alias(self) -> AssetAlias: + return AssetAlias(name=self.name) + + +BaseAssetUniqueKey = Union[AssetUniqueKey, AssetAliasUniqueKey] Review Comment: Just a by-the-way, not sure if you already know—these two classes aren’t actually distinctive due to how nametuples in Python are still fundamentally tuples. Specifically, ```pycon >>> from collections import namedtuple >>> A = namedtuple("A", "x y") >>> B = namedtuple("B", "x y") >>> A(1, 2) == B(1, 2) True ``` The only reason this approach currently works is AssetUniqueKey and AssetAliasUniqueKey have different number of members (2 vs 1). They might as well be free functions returning tuples. Nothing we must change here though (it works after all); we can always fix this later if it fails to work in the future. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org