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

Define and export union types #73

Closed
wants to merge 4 commits into from

Conversation

syou6162
Copy link

@syou6162 syou6162 commented Feb 11, 2024

Background

If I simply use dbt-artifacts-parser, that is often enough, since types like ManifestV1 are provided.

However, if a third-party tool that supports various versions of dbt artifacts uses dbt-artifacts-parser (e.g., datnguye/dbterd#86 ), then the ManifestV1, ManifestV2, ManifestV3, ... types with Union.

We did not think it desirable to define these in third-party tools, since every time there is a change in dbt-artifacts-parser, the third-party tool also has to modify the type.

What I Changed

I defined Union types so that they can be used by third-party libraries.

Copy link

coderabbitai bot commented Feb 11, 2024

Walkthrough

The recent updates in dbt_artifacts_parser/parser.py focus on enhancing type clarity and readability by replacing Union imports with TypeAlias and introducing specific type aliases for Catalog, Manifest, RunResults, and Sources. These changes streamline function signatures and return types, improving code maintainability and readability.

Changes

Files Change Summary
dbt_artifacts_parser/parser.py Updated import statements to use TypeAlias instead of Union, and introduced type aliases for Catalog, Manifest, RunResults, and Sources.

🐇
In the land of code where changes bloom,
TypeAliases dance, dispelling gloom.
Functions now with clarity sing,
Simpler signatures they bring.
A rabbit's joy in each small tweak,
For cleaner code we always seek.
🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@syou6162 syou6162 changed the title Export union types Define and export union types Feb 11, 2024
@syou6162 syou6162 marked this pull request as ready for review February 11, 2024 18:12
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 7

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2171854 and d1a87fd.
Files selected for processing (1)
  • dbt_artifacts_parser/parser.py (5 hunks)
Additional comments: 1
dbt_artifacts_parser/parser.py (1)
  • 82-99: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [74-86]

The Manifest type alias is comprehensive, covering versions 1 through 11. This is a good approach for future-proofing and maintainability.

#
# catalog
#
def parse_catalog(catalog: dict) -> Union[CatalogV1]:
Catalog = Union[CatalogV1]
Copy link

Choose a reason for hiding this comment

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

Ensure the Catalog type alias is future-proof by considering the inclusion of future versions now or implementing a strategy for easy extension.

Comment on lines +48 to +55
def parse_catalog(catalog: dict) -> Catalog:
"""Parse catalog.json

Args:
catalog: dict of catalog.json

Returns:
Union[CatalogV1]
Catalog
Copy link

Choose a reason for hiding this comment

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

The function parse_catalog correctly uses the Catalog type alias. However, consider adding error handling for unexpected dbt_schema_version values to enhance robustness.

Comment on lines 89 to 96
def parse_manifest(manifest: dict) -> Manifest:
"""Parse manifest.json

Args:
manifest: A dict of manifest.json

Returns:
Union[ManifestV1, ManifestV2, ManifestV3, ManifestV4]
Manifest
Copy link

Choose a reason for hiding this comment

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

The parse_manifest function is well-structured and handles multiple versions. Ensure consistency in error messages for better user experience.

Comment on lines 214 to 215
RunResults = Union[RunResultsV1, RunResultsV2, RunResultsV3, RunResultsV4, RunResultsV5]

Copy link

Choose a reason for hiding this comment

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

The RunResults type alias is correctly defined. Consider documenting the rationale for the chosen versions to aid future maintenance.

Comment on lines +217 to +224
def parse_run_results(run_results: dict) -> RunResults:
"""Parse run-results.json

Args:
run_results: A dict of run-results.json

Returns:
Union[RunResultsV1, RunResultsV2, RunResultsV3, RunResultsV4]:
RunResults
Copy link

Choose a reason for hiding this comment

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

In parse_run_results, validate the run_results dict structure before parsing to prevent potential runtime errors.

Comment on lines 282 to 283
Sources = Union[SourcesV1, SourcesV2, SourcesV3]

Copy link

Choose a reason for hiding this comment

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

The Sources type alias includes versions 1 through 3. This is appropriate, but document the process for adding new versions.

Comment on lines +285 to +292
def parse_sources(sources: dict) -> Sources:
"""Parse sources.json

Args:
sources: A dict of sources.json

Returns:
Union[SourcesV1, SourcesV2, SourcesV3]
Sources
Copy link

Choose a reason for hiding this comment

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

parse_sources function should handle unexpected dbt_schema_version values more gracefully to improve error reporting.

@syou6162
Copy link
Author

@yu-iskw Could you review my pull request? CC: @datnguye

@yu-iskw
Copy link
Owner

yu-iskw commented May 22, 2024

@syou6162 I'm so sorry for the delay of my reply and thank you for the contribution. As we have supported dbt 1.8 (manifest v12 and run-results v6) are migrating the supported version of pydantic from v1 to v2, we have some conflicts in the pull request. Can you please catch up with the changes?

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between d1a87fd and 7a71273.
Files selected for processing (1)
  • dbt_artifacts_parser/parser.py (6 hunks)
Additional Context Used
Ruff (1)
dbt_artifacts_parser/parser.py (1)

227-227: SyntaxError: Expected a statement

Additional comments not posted (6)
dbt_artifacts_parser/parser.py (6)

17-17: Ensure the new imports are utilized effectively throughout the module.


47-47: The introduction of the Catalog type alias is a good practice for simplifying type annotations and improving code readability.


50-57: The function parse_catalog correctly uses the Catalog type alias. Consider adding error handling for unexpected dbt_schema_version values to enhance robustness.


Line range hint 76-89: The Manifest type alias is well-defined, covering all current versions. This is a scalable approach that accommodates future versions easily.


92-99: The function parse_manifest is well-structured and handles multiple versions. Ensure consistency in error messages for better user experience.


311-321: The Sources type alias and the parse_sources function are correctly implemented. Ensure that error handling is robust and consider future versions when raising exceptions.

dbt_artifacts_parser/parser.py Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7a71273 and 5c4d793.
Files selected for processing (1)
  • dbt_artifacts_parser/parser.py (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • dbt_artifacts_parser/parser.py

@syou6162
Copy link
Author

@yu-iskw Of course! I have just corrected the conflicted content in 0163006. Can you review it again?

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 5c4d793 and d605861.
Files selected for processing (1)
  • dbt_artifacts_parser/parser.py (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • dbt_artifacts_parser/parser.py

@yu-iskw
Copy link
Owner

yu-iskw commented May 22, 2024

Unfortunately, it seems that we can't use the type aliasing in python 3.8 and 3.9. The two are sill supported versions, though I am not sure how many users are impacted by cutting them off. Do you have any idea to solve the issue?

https://devguide.python.org/versions/

@syou6162
Copy link
Author

@yu-iskw Okay, I understand the situation. Since I could not come up with a replacement for TypeAlias, how about merge this pull request around 2025-10 when Python 3.9 is end of life? I have no problem with waiting until that time.

CC: @datnguye

@yu-iskw
Copy link
Owner

yu-iskw commented May 22, 2024

Alright. Let me close this at the moment. We will have other conflicts as supporting newer versions of dbt, since there is a long time until the end-of-life of the version. Please feel free to reopen it, if it gets ready.

@yu-iskw yu-iskw closed this May 22, 2024
@syou6162 syou6162 deleted the feature/add_union_types branch May 22, 2024 02:25
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.

None yet

2 participants