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

refactor: Use dataclasses to make type safer #2391

Closed
wants to merge 1 commit into from

Conversation

aahung
Copy link
Contributor

@aahung aahung commented Nov 19, 2020

Which issue(s) does this change fix?

Why is this change necessary?

This was originally a part of #2385

With the intro of the following dataclass, mypy can typecheck them so we won't mis-spell dict keys.

  • TemplateOption
  • RuntimeDepInfo

How does it address the issue?

What side effects does this change have?

Checklist

  • Write design document (Do I need to write a design document?)
  • Write unit tests
  • Write/update functional tests
  • Write/update integration tests
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@aahung aahung requested a review from hoffa November 19, 2020 00:57
@hoffa hoffa changed the title chore: Use dataclasses to make type safer refactor: Use dataclasses to make type safer Nov 19, 2020
Comment on lines +115 to +125
templates = [
TemplateOption(
obj.get("directory", None),
obj.get("displayName", None),
obj.get("dependencyManager", None),
obj.get("appTemplate", None),
obj.get("initLocation", None),
obj.get("isDynamicTemplate", None),
)
for obj in raw_templates
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying to a typed object feels weird and wasteful; can we use TypedDicts instead?

@aahung aahung closed this Jan 21, 2021
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.

2 participants