Skip to content

Commit

Permalink
Implement custom __eq__ for subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Nov 26, 2024
1 parent 364dac2 commit f552f8f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions task_sdk/src/airflow/sdk/definitions/asset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ def __init__(
def __fspath__(self) -> str:
return self.uri

def __eq__(self, other: Any) -> bool:
# The Asset class can be subclassed, and we don't want fields added by a
# subclass to break equality. This explicitly filters out only fields
# defined by the Asset class for comparison.
if not isinstance(other, Asset):
return NotImplemented
f = attrs.filters.include(*attrs.fields_dict(Asset))
return attrs.asdict(self, filter=f) == attrs.asdict(other, filter=f)

@property
def normalized_uri(self) -> str | None:
"""
Expand Down

0 comments on commit f552f8f

Please sign in to comment.