Should `AssetIn` behave like pydantic’s Field? It...
# dagster-feedback
d
Should
AssetIn
behave like pydantic’s Field? It would be possible to make assets more readable:
Copy code
@asset
def my_asset(upstream: pd.DataFrame = AssetIn(metadata={"columns": ["A", "B"]})):
    ...
@sandy @schrockn
👀 1
plus1 1
PEP-539 - typing.Annotated - seems very relevant to this topic. FastAPI started using it recently.
hey @schrockn, did you think about this? just curious if you think this makes any sense
s
Hey @Daniel Gafni thanks for your patience here. I’ve been traveling for the last week and a half. I think using Annotated to co-locate
AssetIn
with the parameters they are associated with is potentially quite awesome actually. I don’t think your original suggestion is possible because that would set the default value to
AssetIn
unless that is leveraging some Python feature that I don’t know about.
d
Thanks Jick, forgive me for the impatience. I believe using AssetIn for default values would work too - Pydantic, FastAPI, Typer and some other tools are using this pattern. You would just have to handle these defaults in your decorator. Typer example:
Copy code
import typer


def main(name: str = typer.Argument(...)):
    print(f"Hello {name}")


if __name__ == "__main__":
    typer.run(main)
This CLI program would fail if you don't supply an argument, because Typer treats
typer.Argument(...)
as a missing value for a required field. The
...
is an Ellipsis here (not some missing code). Pydantic example:
Copy code
from pydantic import BaseModel, Field


class Model(BaseModel):
    a: int
    b: int = ...
    c: int = Field(...)  # Ellipsis again
All
a
,
b
and
c
fields are required. You could do the same by handling default `AssetIn`s correctly. So this shouldn't be a problem. Anyway, that's up to you to decide which of the approaches would be more clear and readable for the end-user and better for Dagster. But both should work. I suggest to take a look at how FastAPI is using
Annotated
.
*Nick - typo lol
It seems like Annotated provides information about the type, not about the instance. So perhaps AssetIn as default values would make more sense.