Skip to content

Commit

Permalink
Slight tweaks to field handling in tutorial.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidCEllis committed Jun 7, 2024
1 parent 5ffdcb1 commit 7de40a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ Demonstrate the output of this gatherer:
class GathererTest:
__fields__ = {
"field_1": "First Field",
"field_2": dtbuild.Field(default="Second Field"),
"field_3": CustomField(default="Third Field", report=False)
"field_2": CustomField(default="Second Field"),
"field_3": CustomField(default="Third Field", report=False),
}

pp(fields_attribute_gatherer(GathererTest))
Expand Down
10 changes: 4 additions & 6 deletions docs_code/tutorial_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ def fields_attribute_gatherer(cls_or_ns):

gathered_fields = {}

# Field or CustomField instances will be copied and converted if needed
# Plain values will be made into CustomField instances
for k, v in cls_fields_attrib.items():
if isinstance(v, dtbuild.Field):
gathered_fields[k] = CustomField.from_field(v)
if isinstance(v, CustomField):
gathered_fields[k] = v
else:
gathered_fields[k] = CustomField(default=v)

Expand All @@ -47,8 +45,8 @@ def fields_attribute_gatherer(cls_or_ns):
class GathererTest:
__fields__ = {
"field_1": "First Field",
"field_2": dtbuild.Field(default="Second Field"),
"field_3": CustomField(default="Third Field", report=False)
"field_2": CustomField(default="Second Field"),
"field_3": CustomField(default="Third Field", report=False),
}

pp(fields_attribute_gatherer(GathererTest))
Expand Down

0 comments on commit 7de40a2

Please sign in to comment.