r-richmond edited a comment on issue #14396:
URL: https://github.com/apache/airflow/issues/14396#issuecomment-785517704
>Seems like we end up with ever compiicating interfaces for no benefit other
than "newer" approach where we have simpler alternative.
I'd argue that the dataclass interface is clear than the dictionary
interface and thus simpler to use, although perhaps not as simple to author.
>Now, let me see how would you like to implement backward-compatibility of
this (this is the more standard case of custom operator. This is just copy of
what we have in our documentation:
>What solution would be good here if we use Dataclasses, we want to keep
backwards compatibility and we want to give users typehint for context.
>Any idea how to do it short of converting the Dataclass to TypeDict before
calling execute (which would defeat the purpose of having Dataclass in the
first place).?
First off great challenge :) , 2nd I'd probably replace my earlier
suggestion with the following as well
```python
from dataclasses import dataclass, asdict
@dataclass
class Demo: # context replacement
id: str
value_dc: int
def __getitem__(self, item):
logging.warning(msg=f"dictionary interface is deprecated please
update this to use the dataclass interface")
return asdict(self)[item]
def items(self):
logging.warning(msg=f"dictionary interface is deprecated please
update this to use the dataclass interface")
return asdict(self).items()
def keys(self):
logging.warning(msg=f"dictionary interface is deprecated please
update this to use the dataclass interface")
return asdict(self).keys()
def values(self):
logging.warning(msg=f"dictionary interface is deprecated please
update this to use the dataclass interface")
return asdict(self).values()
d = Demo(id="long_id", value_dc=1337)
print(d["id"])
```
returns
```
WARNING:root:dictionary interface is deprecated please update this to use
the dataclass interface
long_id
```
Seems like this would allow us to go straight to dataclasses without
changing any functions or operators anywhere. We could then deprecate the
dictionary api at the next major version.
What do you think? Is there another use case that I'm not aware of that this
won't work for?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]