Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use typing.Annotation for tagging (and remove autofill). #344

Merged
merged 0 commits into from
Mar 28, 2023

Conversation

copybara-service[bot]
Copy link

Use typing.Annotation for tagging (and remove autofill).

Until this change, there are 2 ways to tag a field in Fiddle: (1) using the
imperative fiddle.set_tags (and
friends
)
API, and (2) the data-flow MyTag.new(some_value) approach. Both of these
work well, but it's convenient to have a more declarative API.

This change allows a library to tag fields in a dataclass or parameters to a
function using typing.Annotated. For example:

@dataclasses.dataclass
class MyDataclass:
  x: typing.Annotated[int, MyTag]
  y: typing.Annotated[str, OneTag, TwoTags] = 'why?'


def annotations_on_functions(
  a: typing.Annotated[float, FloatyTag] = 4.2,
):
  ...

Autofill first explored leveraging the typing.Annotation design. The
lessons learned from that are being incorporated into the next-generation
design of tagging.

@copybara-service copybara-service bot force-pushed the test_519315335 branch 11 times, most recently from f74c7fc to 04d837a Compare March 28, 2023 17:30
@copybara-service copybara-service bot closed this Mar 28, 2023
@copybara-service copybara-service bot merged commit 0804c1c into main Mar 28, 2023
@copybara-service copybara-service bot deleted the test_519315335 branch March 28, 2023 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants