Skip to content

Commit 7351009

Browse files
authored
[du] full sending on type annotations (#21726)
## Summary & Motivation ## How I Tested These Changes
1 parent 11011ab commit 7351009

20 files changed

+51
-35
lines changed

docs/dagster-university/pages/dagster-essentials/extra-credit/asset-metadata-as-markdown.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ In Lesson 9, you created the `adhoc_request` asset. During materialization, the
3232
end_date: str
3333

3434
@asset
35-
def adhoc_request(config: AdhocRequestConfig, taxi_zones, taxi_trips, database: DuckDBResource):
35+
def adhoc_request(config: AdhocRequestConfig, taxi_zones, taxi_trips, database: DuckDBResource) -> None:
3636
"""
3737
The response to an request made in the `requests` directory.
3838
See `requests/README.md` for more information.
@@ -148,7 +148,7 @@ class AdhocRequestConfig(Config):
148148
end_date: str
149149

150150
@asset
151-
def adhoc_request(config: AdhocRequestConfig, taxi_zones, taxi_trips, database: DuckDBResource):
151+
def adhoc_request(config: AdhocRequestConfig, taxi_zones, taxi_trips, database: DuckDBResource) -> None:
152152
"""
153153
The response to an request made in the `requests` directory.
154154
See `requests/README.md` for more information.

docs/dagster-university/pages/dagster-essentials/extra-credit/coding-practice-metadata-taxi-zones-file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ from dagster import MaterializeResult
2121
@asset(
2222
group_name="raw_files",
2323
)
24-
def taxi_zones_file():
24+
def taxi_zones_file() -> None:
2525
"""
2626
The raw CSV file for the taxi zones dataset. Sourced from the NYC Open Data portal.
2727
"""

docs/dagster-university/pages/dagster-essentials/extra-credit/definition-metadata-asset-descriptions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Docstrings are defined by including a string, surrounded by triple quotes (`”
2323
from dagster import asset
2424

2525
@asset
26-
def taxi_zones_file():
26+
def taxi_zones_file() -> None:
2727
"""
2828
The raw CSV file for the taxi zones dataset. Sourced from the NYC Open Data portal.
2929
"""
@@ -49,7 +49,7 @@ from dagster import asset
4949
@asset(
5050
description="The raw CSV file for the taxi zones dataset. Sourced from the NYC Open Data portal."
5151
)
52-
def taxi_zones_file():
52+
def taxi_zones_file() -> None:
5353
"""
5454
This will not show in the Dagster UI
5555
"""

docs/dagster-university/pages/dagster-essentials/extra-credit/definition-metadata-asset-groups.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ from dagster import asset
5656
@asset(
5757
group_name="raw_files",
5858
)
59-
def taxi_zones_file():
59+
def taxi_zones_file() -> None:
6060
"""
6161
The raw CSV file for the taxi zones dataset. Sourced from the NYC Open Data portal.
6262
"""

docs/dagster-university/pages/dagster-essentials/extra-credit/materialization-metadata.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Let’s add metadata to the `taxi_trips_file` asset to demonstrate further. This
3333
partitions_def=monthly_partition,
3434
group_name="raw_files",
3535
)
36-
def taxi_trips_file(context):
36+
def taxi_trips_file(context) -> None:
3737
"""
3838
The raw parquet files for the taxi trips dataset. Sourced from the NYC Open Data portal.
3939
"""
@@ -65,8 +65,22 @@ Let’s add metadata to the `taxi_trips_file` asset to demonstrate further. This
6565
)
6666
```
6767

68+
5. Then, since we're now returning something, let's update the return type of the asset to `MaterializeResult`:
69+
70+
```python
71+
from dagster import asset, MaterializeResult
72+
73+
@asset(
74+
partitions_def=monthly_partition,
75+
group_name="raw_files",
76+
)
77+
def taxi_trips_file(context) -> MaterializeResult:
78+
```
79+
80+
6881
Let’s break down what’s happening here:
6982

83+
- Rather than returning nothing, we'll return some information about the materialization that happened with the `MaterializationResult` class.
7084
- The `metadata` parameter accepts a `dict`, where the key is the label or name of the metadata and the value is the data itself. In this case, the key is `Number of records`. The value in this example is everything after `Number of records`.
7185
- Using `MetadataValue.int`, the value of the `num_rows` variable is typed as an integer. This tells Dagster to render the data as an integer.
7286

@@ -80,7 +94,7 @@ Let’s add metadata to the `taxi_trips_file` asset to demonstrate further. This
8094
partitions_def=monthly_partition,
8195
group_name="raw_files",
8296
)
83-
def taxi_trips_file(context):
97+
def taxi_trips_file(context) -> MaterializeResult:
8498
"""
8599
The raw parquet files for the taxi trips dataset. Sourced from the NYC Open Data portal.
86100
"""

docs/dagster-university/pages/dagster-essentials/lesson-3/asset-materialization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ To better understand how materialization works, let’s take another look at the
1212

1313
```python file=/dagster-university/lesson_3.py startafter=start_taxi_trips_file_asset endbefore=end_taxi_trips_file_asset
1414
@asset
15-
def taxi_trips_file():
15+
def taxi_trips_file() -> None:
1616
"""The raw parquet files for the taxi trips dataset. Sourced from the NYC Open Data portal."""
1717
month_to_fetch = "2023-03"
1818
raw_trips = requests.get(

docs/dagster-university/pages/dagster-essentials/lesson-3/coding-practice-taxi-zones-file-asset.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The asset you built should look similar to the following code. Click **View answ
2222

2323
```python {% obfuscated="true" %}
2424
@asset
25-
def taxi_zones_file():
25+
def taxi_zones_file() -> None:
2626
"""
2727
The raw CSV file for the taxi zones dataset. Sourced from the NYC Open Data portal.
2828
"""

docs/dagster-university/pages/dagster-essentials/lesson-3/defining-your-first-asset.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ Your first asset, which you’ll name `taxi_trips_file`, will retrieve the yello
1919
from . import constants
2020
```
2121

22-
3. Below the imports, add the following code to create a function named `taxi_trips_file`:
22+
3. Below the imports, let's define a function that takes no inputs and returns nothing (type-annoted with `None`). Add the following code to create a function to do this named `taxi_trips_file`:
2323

2424
```python
25-
def taxi_trips_file():
25+
def taxi_trips_file() -> None:
2626
"""
2727
The raw parquet files for the taxi trips dataset. Sourced from the NYC Open Data portal.
2828
"""
@@ -51,7 +51,7 @@ Your first asset, which you’ll name `taxi_trips_file`, will retrieve the yello
5151
from dagster import asset
5252

5353
@asset
54-
def taxi_trips_file():
54+
def taxi_trips_file() -> None:
5555
"""
5656
The raw parquet files for the taxi trips dataset. Sourced from the NYC Open Data portal.
5757
"""
@@ -65,3 +65,5 @@ Your first asset, which you’ll name `taxi_trips_file`, will retrieve the yello
6565
```
6666

6767
That’s it - you’ve created your first Dagster asset! Using the `@asset` decorator, you can easily turn any existing Python function into a Dagster asset.
68+
69+
**Questions about the `-> None` bit?** That's a Python feature called **type annotation**. In this case, it's saying that the function returns nothing. You can learn more about type annotations in the [Python documentation](https://docs.python.org/3/library/typing.html). We highly recommend using type annotations in your code to make it easier to read and understand.

docs/dagster-university/pages/dagster-essentials/lesson-3/troubleshooting-failed-runs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import requests
1616
from dagster import asset
1717

1818
@asset
19-
def taxi_trips_file():
19+
def taxi_trips_file() -> None:
2020
"""
2121
The raw parquet files for the taxi trips dataset. Sourced from the NYC Open Data portal.
2222
"""

docs/dagster-university/pages/dagster-essentials/lesson-4/assets-with-in-memory-computations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Having all of your assets in one file becomes difficult to manage. Let’s separ
3737
@asset(
3838
deps=["taxi_trips", "taxi_zones"]
3939
)
40-
def manhattan_stats():
40+
def manhattan_stats() -> None:
4141
```
4242

4343
4. Now, let’s add the logic to calculate `manhattan_stats`. Update the `manhattan_stats` asset definition to reflect the changes below:
@@ -46,7 +46,7 @@ Having all of your assets in one file becomes difficult to manage. Let’s separ
4646
@asset(
4747
deps=["taxi_trips", "taxi_zones"]
4848
)
49-
def manhattan_stats():
49+
def manhattan_stats() -> None:
5050
query = """
5151
select
5252
zones.zone,
@@ -96,7 +96,7 @@ In this section, you’ll create an asset that depends on `manhattan_stats`, loa
9696
@asset(
9797
deps=["manhattan_stats"],
9898
)
99-
def manhattan_map():
99+
def manhattan_map() -> None:
100100
trips_by_zone = gpd.read_file(constants.MANHATTAN_STATS_FILE_PATH)
101101

102102
fig = px.choropleth_mapbox(trips_by_zone,

0 commit comments

Comments
 (0)