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

feat: well-defined type comparison semantics #846

Merged
merged 11 commits into from
Sep 18, 2024
Merged

Conversation

Natoandro
Copy link
Contributor

@Natoandro Natoandro commented Sep 12, 2024

Solve MET-655

  • Document the type comparison semantics
  • Improve the implementation (EnsureSubtypeOf trait)
  • Add more test cases for type comparisons

Migration notes

No change is needed.

...

  • The change comes with new or modified tests
  • Hard-to-understand functions have explanatory comments
  • End-user documentation is updated to reflect the change

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced comprehensive type comparison rules and semantics for scalar types, optionals, lists, objects, and unions.
    • Added support for enumerated types in the type system, allowing for more precise type definitions.
    • Enhanced parent injection mechanism documentation to clarify type compatibility requirements.
    • Implemented a new suite of type comparison tests and validation mechanisms.
  • Bug Fixes

    • Improved error reporting and handling in the type validation process.
  • Documentation

    • Updated and expanded documentation for type comparisons, enumerations, and parent injections.
  • Tests

    • Added new tests for type comparison and validation scenarios.

Copy link

linear bot commented Sep 12, 2024

@Natoandro Natoandro changed the title doc: Type comparison semantics docs: Type comparison semantics Sep 12, 2024
Copy link
Contributor

@michael-0acf4 michael-0acf4 left a comment

Choose a reason for hiding this comment

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

Overall looks great maybe we can add some examples for the tricky ones.

Copy link
Contributor

@Yohe-Am Yohe-Am left a comment

Choose a reason for hiding this comment

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

Enumerations seem to be missing but looking good.

@Natoandro Natoandro marked this pull request as ready for review September 16, 2024 13:34
@Natoandro Natoandro changed the title docs: Type comparison semantics feat: well-defined type comparison semantics Sep 17, 2024
@Natoandro
Copy link
Contributor Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Sep 18, 2024

Walkthrough

The changes introduce enhancements to the type system documentation and validation logic within the codebase. Key updates include the addition of type comparison rules, support for enumerations, and clarifications on subtype requirements in injection mechanisms. The validation process has been improved with new structures for error handling and subtype checks. Additionally, comprehensive tests for type comparisons have been implemented to ensure correct behavior across various data types.

Changes

Files Change Summary
docs/metatype.dev/docs/reference/types/comparison.mdx Added comprehensive framework for type comparison, detailing relationships and rules for scalar types, optionals, lists, objects, and unions.
docs/metatype.dev/docs/reference/types/index.mdx Introduced enumerations for types, allowing specific valid values through examples in Python and TypeScript.
docs/metatype.dev/docs/reference/types/injections.mdx Clarified that source types must be subtypes of target types in parent injection documentation.
src/common/src/typegraph/types.rs Modified Float variant label from "number" to "float" for clarity in type representation.
src/common/src/typegraph/validator/mod.rs Added Layer struct for structured type traversal and improved error handling in validate_typegraph.
src/common/src/typegraph/validator/types.rs Enhanced EnsureSubtypeOf trait, added methods for better error reporting, and introduced new structures for subtype validation.
src/common/src/typegraph/visitor.rs Introduced VisitLayer trait for customizable type traversal and modified related methods for improved flexibility.
tests/schema_validation/type_comparison.py Implemented type comparison tests covering various data types and ensuring correct subtype relationships.
tests/schema_validation/type_comparison_test.ts Created test case for validating type comparison errors, capturing and asserting error messages from Python script execution.

Suggested reviewers

  • coderabbitai

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>, please review it.
    -- 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 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.
    -- @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

Copy link
Contributor

@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: 2

Outside diff range and nitpick comments (10)
docs/metatype.dev/docs/reference/types/comparison.mdx (7)

14-14: Consider adding a comma for clarity.

To improve readability, consider adding a comma after "In this section" as suggested by the static analysis hint.

-In this section `A` and `B` denote types, `U` and `V` denote lists of types.
+In this section, `A` and `B` denote types, `U` and `V` denote lists of types.
Tools
LanguageTool

[uncategorized] ~14-~14: Possible missing comma found.
Context: ...ections#parent). ## Semantics In this section A and B denote types, U and V d...

(AI_HYDRA_LEO_MISSING_COMMA)


25-26: Rephrase for clarity and grammatical correctness.

To improve clarity and address the grammatical issues flagged by the static analysis hints, consider rephrasing the sentence as follows:

-If `A` is a subtype of `B` and `B` is a scalar type then
-    `A` is a scalar type of a union type in which any variant is a subtype of `B`.
+If `A` is a subtype of `B`, and `B` is a scalar type, then
+    `A` is either a scalar type or a union type in which any variant is a subtype of `B`.
Tools
LanguageTool

[uncategorized] ~25-~25: Possible missing comma found.
Context: ...is a subtype of B and B is a scalar type then A is a scalar type of a unio...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~26-~26: If ‘type’ is a classification term, ‘a’ is not necessary. Use “type of”. (The phrases ‘kind of’ and ‘sort of’ are informal if they mean ‘to some extent’.)
Context: ... a scalar type then A is a scalar type of a union type in which any variant is a su...

(KIND_OF_A)


30-30: Add missing article for grammatical correctness.

To address the grammatical issue flagged by the static analysis hint, add the missing article "a" as follows:

-Then `A` is subtype of `B` if and only if the following conditions hold:
+Then `A` is a subtype of `B` if and only if the following conditions hold:
Tools
LanguageTool

[uncategorized] ~30-~30: You might be missing the article “a” here.
Context: ... B are scalar types. Then A is subtype of B if and only if the following con...

(AI_EN_LECTOR_MISSING_DETERMINER_A)


60-60: Add missing article for grammatical correctness.

To address the grammatical issue flagged by the static analysis hint, add the missing article "a" as follows:

-`A` is a subtype of `t.optional(B)` if and only if `A` is subtype of `B`.
+`A` is a subtype of `t.optional(B)` if and only if `A` is a subtype of `B`.
Tools
LanguageTool

[uncategorized] ~60-~60: You might be missing the article “a” here.
Context: ...f t.optional(B) if and only if A is subtype of B. 2. t.optional(A) is a subtyp...

(AI_EN_LECTOR_MISSING_DETERMINER_A)


69-69: Fix the spelling of "vice versa".

To address the grammatical issue flagged by the static analysis hint, remove the hyphen from "vice-versa" as follows:

-If `A` is a list then `B` is a list and vice-versa.
+If `A` is a list then `B` is a list and vice versa.

-If `A` is an object type then `B` is an object type, and vice-versa.
+If `A` is an object type then `B` is an object type, and vice versa.

Also applies to: 87-87

Tools
LanguageTool

[grammar] ~69-~69: The expression “vice versa” is spelled without hyphens.
Context: ...If A is a list then B is a list and vice-versa. 2. Let X a list type whose item typ...

(VICE_VERSA)


87-87: Consider adding commas for clarity.

To improve readability, consider adding commas as suggested by the static analysis hints:

-If `A` is an object type then `B` is an object type, and vice versa.
+If `A` is an object type, then `B` is an object type, and vice versa.

-If `A` is a type and `V` a list of types then
+If `A` is a type, and `V` a list of types, then

-If `A` is a type and `V` a list of types then
+If `A` is a type, and `V` a list of types, then

Also applies to: 103-103, 107-107

Tools
LanguageTool

[uncategorized] ~87-~87: Possible missing comma found.
Context: ... subtype of B. If A is an object type then B is an object type, and vice-ve...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~87-~87: The expression “vice versa” is spelled without hyphens.
Context: ...ct type then B is an object type, and vice-versa. 2. If A and B are object types, t...

(VICE_VERSA)


51-51: Consider a shorter alternative for "exactly the same".

While "exactly the same" is a common phrase, using a shorter alternative can improve conciseness. Consider using "identical" or simply "the same" to convey the same meaning more concisely.

-The patterns are required to be exactly the same
+The patterns are required to be identical
Tools
LanguageTool

[style] ~51-~51: ‘exactly the same’ might be wordy. Consider a shorter alternative.
Context: ...[^pat]: The patterns are required to be exactly the same because we currently do not hav...

(EN_WORDINESS_PREMIUM_EXACTLY_THE_SAME)

tests/schema_validation/type_comparison.py (2)

76-104: Good test coverage for file type comparison with some follow-up items!

The test cases cover a comprehensive set of scenarios for file type comparison, including min, max, and allow constraints. The test cases are correctly structured to check both successful type matches and expected failures.

However, there are two items that require follow-up:

  1. The TODO comment at line 93 indicates that support for wildcards in the allow constraint is missing. This should be addressed in the future to enhance the functionality of the file type comparison.
  2. The FIXME comment at line 95 indicates that there is a potential issue with the test case "file_fail_1" where it is expected to fail but it doesn't. This should be investigated and fixed to ensure the correctness of the test suite.

Do you want me to open GitHub issues to track these follow-up items?


185-191: Good test coverage for enum type comparison with a follow-up item!

The test cases cover scenarios where enum subtypes are compared with enum supertypes and non-enum types. The test cases are correctly structured to check both successful type matches and expected failures.

However, there is a TODO comment at line 188 indicating that a test case for comparing float enum with integer enum is missing. This should be added in the future to enhance the coverage of the enum type comparison test suite.

Do you want me to open a GitHub issue to track this follow-up item?

docs/metatype.dev/docs/reference/types/index.mdx (1)

112-113: Improve readability by adding a comma.

Consider adding a comma after the introductory phrase "In this case" for better readability:

-In this case the only valid values for the type are the ones that are listed in the enumeration.
+In this case, the only valid values for the type are the ones that are listed in the enumeration.
Tools
LanguageTool

[uncategorized] ~112-~112: Loose punctuation mark.
Context: ...DKTabs> ### Enumerations t.integer(), t.float(), t.string(), `t.struct(.....

(UNLIKELY_OPENING_PUNCTUATION)


[formatting] ~112-~112: Consider inserting a comma after an introductory phrase for better readability.
Context: ...` can have a list of enumerated values. In this case the only valid values for the type are ...

(IN_THAT_CASE_COMMA)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d35f5c3 and ddeec77.

Files ignored due to path filters (2)
  • tests/e2e/typegraph/__snapshots__/validator_test.ts.snap is excluded by !**/*.snap
  • tests/schema_validation/__snapshots__/type_comparison_test.ts.snap is excluded by !**/*.snap
Files selected for processing (9)
  • docs/metatype.dev/docs/reference/types/comparison.mdx (1 hunks)
  • docs/metatype.dev/docs/reference/types/index.mdx (1 hunks)
  • docs/metatype.dev/docs/reference/types/injections.mdx (1 hunks)
  • src/common/src/typegraph/types.rs (1 hunks)
  • src/common/src/typegraph/validator/mod.rs (2 hunks)
  • src/common/src/typegraph/validator/types.rs (3 hunks)
  • src/common/src/typegraph/visitor.rs (7 hunks)
  • tests/schema_validation/type_comparison.py (1 hunks)
  • tests/schema_validation/type_comparison_test.ts (1 hunks)
Additional context used
LanguageTool
docs/metatype.dev/docs/reference/types/comparison.mdx

[uncategorized] ~14-~14: Possible missing comma found.
Context: ...ections#parent). ## Semantics In this section A and B denote types, U and V d...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~25-~25: Possible missing comma found.
Context: ...is a subtype of B and B is a scalar type then A is a scalar type of a unio...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~26-~26: If ‘type’ is a classification term, ‘a’ is not necessary. Use “type of”. (The phrases ‘kind of’ and ‘sort of’ are informal if they mean ‘to some extent’.)
Context: ... a scalar type then A is a scalar type of a union type in which any variant is a su...

(KIND_OF_A)


[uncategorized] ~30-~30: You might be missing the article “a” here.
Context: ... B are scalar types. Then A is subtype of B if and only if the following con...

(AI_EN_LECTOR_MISSING_DETERMINER_A)


[style] ~51-~51: ‘exactly the same’ might be wordy. Consider a shorter alternative.
Context: ...[^pat]: The patterns are required to be exactly the same because we currently do not hav...

(EN_WORDINESS_PREMIUM_EXACTLY_THE_SAME)


[uncategorized] ~60-~60: You might be missing the article “a” here.
Context: ...f t.optional(B) if and only if A is subtype of B. 2. t.optional(A) is a subtyp...

(AI_EN_LECTOR_MISSING_DETERMINER_A)


[grammar] ~69-~69: The expression “vice versa” is spelled without hyphens.
Context: ...If A is a list then B is a list and vice-versa. 2. Let X a list type whose item typ...

(VICE_VERSA)


[uncategorized] ~87-~87: Possible missing comma found.
Context: ... subtype of B. If A is an object type then B is an object type, and vice-ve...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~87-~87: The expression “vice versa” is spelled without hyphens.
Context: ...ct type then B is an object type, and vice-versa. 2. If A and B are object types, t...

(VICE_VERSA)


[uncategorized] ~103-~103: Possible missing comma found.
Context: ... 1. If A is a type and V a list of types then A is a subtype of `t.union(V...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~107-~107: Possible missing comma found.
Context: ... 2. If A is a type and V a list of types then A is a subtype of `t.either(...

(AI_HYDRA_LEO_MISSING_COMMA)

docs/metatype.dev/docs/reference/types/index.mdx

[uncategorized] ~112-~112: Loose punctuation mark.
Context: ...DKTabs> ### Enumerations t.integer(), t.float(), t.string(), `t.struct(.....

(UNLIKELY_OPENING_PUNCTUATION)


[formatting] ~112-~112: Consider inserting a comma after an introductory phrase for better readability.
Context: ...` can have a list of enumerated values. In this case the only valid values for the type are ...

(IN_THAT_CASE_COMMA)

Additional comments not posted (38)
docs/metatype.dev/docs/reference/types/injections.mdx (1)

18-18: Documentation update looks good!

The added requirement clarifies the type compatibility constraint for the parent injection mechanism. This is an important point to ensure type safety during dependency resolution.

The change improves the documentation by making it more complete and easier to understand.

src/common/src/typegraph/validator/mod.rs (4)

12-13: LGTM!

The additional imports are necessary for the subsequent changes to implement the new layer of functionality for type graph validation.


19-19: LGTM!

The inclusion of the Layer parameter in the traverse_types method call indicates a more structured approach to visiting nodes within the type graph. This change aligns with the overall objective of improving the type graph validation process.


38-60: LGTM!

The introduction of the Layer struct and its implementation of the VisitLayer trait for the Validator enhances the structure and error handling capabilities of the type graph validation process. The visit method's logic for iterating over child nodes and collecting errors provides a more granular approach to handling validation errors during the traversal.


61-61: LGTM!

The addition of the empty line improves the readability and organization of the code by visually separating the Layer struct implementation from the subsequent code.

docs/metatype.dev/docs/reference/types/comparison.mdx (4)

1-11: Excellent introduction to subtyping and type comparison!

The introduction provides a clear and concise explanation of subtyping, using the analogy of the "is subset of" relation to help readers understand the concept. The mention of the relevance to "from parent" injections provides good context for the importance of type comparison.


12-117: Comprehensive and well-structured semantics section!

The semantics section provides detailed rules and conditions for type comparison in each type category. The use of tables to present the conditions for type constraints enhances readability. The explanations are clear and thorough.

Tools
LanguageTool

[uncategorized] ~14-~14: Possible missing comma found.
Context: ...ections#parent). ## Semantics In this section A and B denote types, U and V d...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~25-~25: Possible missing comma found.
Context: ...is a subtype of B and B is a scalar type then A is a scalar type of a unio...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~26-~26: If ‘type’ is a classification term, ‘a’ is not necessary. Use “type of”. (The phrases ‘kind of’ and ‘sort of’ are informal if they mean ‘to some extent’.)
Context: ... a scalar type then A is a scalar type of a union type in which any variant is a su...

(KIND_OF_A)


[uncategorized] ~30-~30: You might be missing the article “a” here.
Context: ... B are scalar types. Then A is subtype of B if and only if the following con...

(AI_EN_LECTOR_MISSING_DETERMINER_A)


[style] ~51-~51: ‘exactly the same’ might be wordy. Consider a shorter alternative.
Context: ...[^pat]: The patterns are required to be exactly the same because we currently do not hav...

(EN_WORDINESS_PREMIUM_EXACTLY_THE_SAME)


[uncategorized] ~60-~60: You might be missing the article “a” here.
Context: ...f t.optional(B) if and only if A is subtype of B. 2. t.optional(A) is a subtyp...

(AI_EN_LECTOR_MISSING_DETERMINER_A)


[grammar] ~69-~69: The expression “vice versa” is spelled without hyphens.
Context: ...If A is a list then B is a list and vice-versa. 2. Let X a list type whose item typ...

(VICE_VERSA)


[uncategorized] ~87-~87: Possible missing comma found.
Context: ... subtype of B. If A is an object type then B is an object type, and vice-ve...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~87-~87: The expression “vice versa” is spelled without hyphens.
Context: ...ct type then B is an object type, and vice-versa. 2. If A and B are object types, t...

(VICE_VERSA)


[uncategorized] ~103-~103: Possible missing comma found.
Context: ... 1. If A is a type and V a list of types then A is a subtype of `t.union(V...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~107-~107: Possible missing comma found.
Context: ... 2. If A is a type and V a list of types then A is a subtype of `t.either(...

(AI_HYDRA_LEO_MISSING_COMMA)


117-120: Good reference to the type comparison test suite!

Providing a link to the type comparison test suite is helpful for readers who want to see practical examples of type comparison. The section is concise and to the point.


1-120: Excellent document structure and comprehensive content!

The document is well-structured, with clear sections for introduction, semantics, and examples. The content is comprehensive, covering type comparison rules and semantics for various type categories. The explanations are clear and thorough, making effective use of tables and code snippets.

This document serves as a valuable reference for understanding type comparison in the metatype system and provides a solid foundation for developers working with type injections and validation.

Tools
LanguageTool

[uncategorized] ~14-~14: Possible missing comma found.
Context: ...ections#parent). ## Semantics In this section A and B denote types, U and V d...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~25-~25: Possible missing comma found.
Context: ...is a subtype of B and B is a scalar type then A is a scalar type of a unio...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~26-~26: If ‘type’ is a classification term, ‘a’ is not necessary. Use “type of”. (The phrases ‘kind of’ and ‘sort of’ are informal if they mean ‘to some extent’.)
Context: ... a scalar type then A is a scalar type of a union type in which any variant is a su...

(KIND_OF_A)


[uncategorized] ~30-~30: You might be missing the article “a” here.
Context: ... B are scalar types. Then A is subtype of B if and only if the following con...

(AI_EN_LECTOR_MISSING_DETERMINER_A)


[style] ~51-~51: ‘exactly the same’ might be wordy. Consider a shorter alternative.
Context: ...[^pat]: The patterns are required to be exactly the same because we currently do not hav...

(EN_WORDINESS_PREMIUM_EXACTLY_THE_SAME)


[uncategorized] ~60-~60: You might be missing the article “a” here.
Context: ...f t.optional(B) if and only if A is subtype of B. 2. t.optional(A) is a subtyp...

(AI_EN_LECTOR_MISSING_DETERMINER_A)


[grammar] ~69-~69: The expression “vice versa” is spelled without hyphens.
Context: ...If A is a list then B is a list and vice-versa. 2. Let X a list type whose item typ...

(VICE_VERSA)


[uncategorized] ~87-~87: Possible missing comma found.
Context: ... subtype of B. If A is an object type then B is an object type, and vice-ve...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~87-~87: The expression “vice versa” is spelled without hyphens.
Context: ...ct type then B is an object type, and vice-versa. 2. If A and B are object types, t...

(VICE_VERSA)


[uncategorized] ~103-~103: Possible missing comma found.
Context: ... 1. If A is a type and V a list of types then A is a subtype of `t.union(V...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~107-~107: Possible missing comma found.
Context: ... 2. If A is a type and V a list of types then A is a subtype of `t.either(...

(AI_HYDRA_LEO_MISSING_COMMA)

src/common/src/typegraph/types.rs (1)

316-316: LGTM! The label change improves clarity and precision.

The change from "number" to "float" for the Float variant in the type_name method provides a more accurate and specific representation of the type. This enhances code readability and maintainability by avoiding potential confusion between generic numeric types and floating-point types. The change aligns with the principle of using clear and precise naming conventions in the codebase.

tests/schema_validation/type_comparison.py (9)

26-26: LGTM!

The test case is correctly defined and should pass as a boolean type is always compatible with itself.


28-41: Great test coverage for integer type comparison!

The test cases cover a comprehensive set of scenarios for integer type comparison, including min, max, and multiple_of constraints. The test cases are correctly structured to check both successful type matches and expected failures.


43-56: Great test coverage for float type comparison!

The test cases cover a comprehensive set of scenarios for float type comparison, including min, max, and multiple_of constraints. The test cases are correctly structured to check both successful type matches and expected failures.


58-65: Good test coverage for number type comparison!

The test cases cover scenarios where integer subtypes are compared with float supertypes and vice versa. The test cases are correctly structured to check both successful type matches and expected failures.


67-74: Great test coverage for string type comparison!

The test cases cover a comprehensive set of scenarios for string type comparison, including min and max constraints. The test cases are correctly structured to check both successful type matches and expected failures.


106-113: Good test coverage for optional type comparison!

The test cases cover scenarios where optional subtypes are compared with optional supertypes and non-optional types. The test cases are correctly structured to check both successful type matches and expected failures.


115-120: Good test coverage for list type comparison!

The test cases cover scenarios where list subtypes are compared with list supertypes and non-list types. The test cases are correctly structured to check both successful type matches and expected failures.


122-154: Good test coverage for struct type comparison!

The test cases cover scenarios where struct subtypes are compared with struct supertypes and struct types with different field names and types. The test cases are correctly structured to check both successful type matches and expected failures.


156-183: Excellent test coverage for union type comparison!

The test cases cover a wide range of scenarios where union subtypes are compared with union supertypes, either types, and non-union types. The test cases are correctly structured to check both successful type matches and expected failures, ensuring the correctness of the union type comparison logic.

src/common/src/typegraph/visitor.rs (8)

9-11: LGTM!

The DefaultLayer struct is a valid default implementation for the VisitLayer trait. Deriving Clone is necessary to satisfy the trait requirements.


14-21: LGTM!

The VisitLayer trait is a well-designed abstraction for customizable traversal layers. The visit method signature allows for flexible traversal strategies, and the associated types provide extensibility in the visitor and context used.


23-37: LGTM!

The DefaultLayer implementation of VisitLayer provides a sensible default behavior for visiting child nodes. It allows for extensibility by serving as a baseline that can be overridden by custom layers.


39-46: LGTM!

The visit_child function is a useful abstraction that simplifies visiting child nodes. It encapsulates the details of calling the visit_child method on the TypegraphTraversal instance, making it easier for custom layers to visit child nodes.


50-58: LGTM!

The modifications to the traverse_types method enhance the flexibility and extensibility of the type traversal mechanism. The addition of the layer parameter allows for customizable traversal layers, and the Sized trait bound on V ensures that the visitor type can be used as a value.


82-93: LGTM!

The modifications to the TypegraphTraversal struct make it more flexible and extensible. The addition of the layer field allows the traversal to utilize different traversal layers, and the Sized trait bound on V ensures that the visitor type can be used as a value within the traversal.


200-211: LGTM!

The modification to the visit_object method to use the new visit_children method improves the code structure and readability. Mapping the object properties to ChildNode instances and passing them to visit_children aligns with the new traversal layer abstraction and simplifies the process of visiting child nodes.


304-314: LGTM!

The addition of the visit_children method to the TypegraphTraversal struct is a great improvement. It encapsulates the logic for visiting multiple child nodes, abstracting away the details of iteration and delegation to the traversal layer. This method promotes code reuse and enhances the readability of the traversal code.

docs/metatype.dev/docs/reference/types/index.mdx (1)

110-142: LGTM!

The new section on enumerations is a great addition to the type system documentation. The examples clearly demonstrate how to use the .enum() method with various types, and the t.enum(array) alias provides a convenient shorthand for defining string enumerations.

The changes enhance the functionality and usability of the type system by allowing developers to define constrained sets of values for their types.

Tools
LanguageTool

[uncategorized] ~112-~112: Loose punctuation mark.
Context: ...DKTabs> ### Enumerations t.integer(), t.float(), t.string(), `t.struct(.....

(UNLIKELY_OPENING_PUNCTUATION)


[formatting] ~112-~112: Consider inserting a comma after an introductory phrase for better readability.
Context: ...` can have a list of enumerated values. In this case the only valid values for the type are ...

(IN_THAT_CASE_COMMA)

src/common/src/typegraph/validator/types.rs (10)

27-33: LGTM!

The new push_nested method looks good. It allows for nesting of error messages, which can be useful for providing more structured and hierarchical error reporting.


36-37: Great addition!

The inclusion of the generic type parameter T with a default value of Self makes the EnsureSubtypeOf trait more flexible. It allows for cross-type comparisons, such as comparing an IntegerTypeData with a FloatTypeData, which can be very useful in certain scenarios.


41-64: Nice refactoring!

The use of pattern matching instead of nested if let statements improves the readability and maintainability of the code. The logic remains the same, ensuring that the minimum value of the subtype is not lower than the minimum value of the supertype. The error messages are clear and informative.


67-90: Nice refactoring!

The use of pattern matching instead of nested if let statements improves the readability and maintainability of the code. The logic remains the same, ensuring that the maximum value of the subtype is not higher than the maximum value of the supertype. The error messages are clear and informative.


93-116: Nice refactoring!

The use of pattern matching instead of nested if let statements improves the readability and maintainability of the code. The logic remains the same, ensuring that the multiple_of value of the subtype is a multiple of the multiple_of value of the supertype. The error messages are clear and informative.


119-141: LGTM!

The implementation of EnsureSubtypeOf for IntegerTypeData looks good. It properly checks the subtype constraints for minimum, maximum, exclusive_minimum, exclusive_maximum, and multiple_of values using the respective helper functions. This ensures that the IntegerTypeData subtype is compatible with its supertype.


144-166: LGTM!

The implementation of EnsureSubtypeOf for FloatTypeData looks good. It properly checks the subtype constraints for minimum, maximum, exclusive_minimum, exclusive_maximum, and multiple_of values using the respective helper functions. This ensures that the FloatTypeData subtype is compatible with its supertype.


168-206: Great implementation!

The implementation of EnsureSubtypeOf for IntegerTypeData with FloatTypeData as the supertype is a nice addition. It allows for cross-type comparison, ensuring that the minimum, maximum, exclusive_minimum, exclusive_maximum, and multiple_of values of the IntegerTypeData subtype are compatible with the corresponding values of the FloatTypeData supertype. The conversion of IntegerTypeData fields to f64 is handled correctly.


209-245: LGTM!

The implementation of EnsureSubtypeOf for StringTypeData looks good. It properly checks the subtype constraints for min_length, max_length, pattern, and format fields. The min_length and max_length values are verified using the respective helper functions, while the pattern and format fields are checked for exact equality if they are defined on both the subtype and supertype. The error messages are clear and informative.


248-269: LGTM!

The implementation of `

Copy link

codecov bot commented Sep 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.21%. Comparing base (d35f5c3) to head (ddeec77).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #846      +/-   ##
==========================================
- Coverage   76.43%   76.21%   -0.23%     
==========================================
  Files         144      144              
  Lines       16705    16705              
  Branches     1646     1642       -4     
==========================================
- Hits        12769    12732      -37     
- Misses       3917     3954      +37     
  Partials       19       19              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Natoandro Natoandro merged commit 21bae2f into main Sep 18, 2024
12 of 14 checks passed
@Natoandro Natoandro deleted the doc-met-655-subtype branch September 18, 2024 07:44
@coderabbitai coderabbitai bot mentioned this pull request Jan 30, 2025
3 tasks
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.

3 participants