-
Notifications
You must be signed in to change notification settings - Fork 33
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
tftypes: Enhance Type Comparisons Functionality #94
Conversation
Update our Type interface to include UsableAs and Equal explicitly. Add placeholders for UsableAs and Equal on all types, so tests can run. Update String, Number, Bool, and DynamicPseudoType to have UsableAs implementations, and tests for those implementations. DynamicPseudoType will panic when UsableAs is called on it, because DynamicPseudoType is a type constraint, it should never be associated with a Value. This work will allow us to resolve #83.
…() into Equal() and Is() The interface now accounts for the differing semantics of Equal() and Is(), which means the dual purpose equals() method is extraneous.
Prevent issues with DynamicPsuedoType handling.
More accurate behavior after Is() refactoring and prevents panics.
… Object AttributeTypes
…actions so testing does not require adjustment
Leave descriptive comment for future travelers.
… and UsableAs() functionality
… cannot be implemented outside the tftypes package
…accepts matching Type and Value
…t` having `DynamicPseudoType` as their type when unmarshaling JSON values from Terraform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks right to me. Really pleased with how this all came out, really nice work.
I was wrong, you can have null
DynamicPseudoType values. :( We can take care of adding that in another PR, though. I'll open an issue.
Reference: #94 Reference: #99 Reference: #100 Reference: #128 Reference: #133 Reverts incorrect logic for handling DynamicPseudoType values in `tftypes`. This type information must be preserved when traversing the protocol, as Terraform CLI decodes values based on the schema information. If a concrete value type is used where DynamicPseudoType is expected, Terraform CLI will return errors such as (given an object of 4 attributes, when DynamicPseudoType is expected): ``` │ Error: ["manifest"]: msgpack: invalid code=84 decoding array length ```
Reference: #94 Reference: #99 Reference: #100 Reference: #128 Reference: #133 Reverts incorrect logic for handling DynamicPseudoType values in `tftypes`. This type information must be preserved when traversing the protocol, as Terraform CLI decodes values based on the schema information. If a concrete value type is used where DynamicPseudoType is expected, Terraform CLI will return errors such as (given an object of 4 attributes, when DynamicPseudoType is expected): ``` │ Error: ["manifest"]: msgpack: invalid code=84 decoding array length ```
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Closes #80
Each type now implements three separate and distinct comparison methods:
(T).Equal()
: performs deep type equality checks, including attribute/element types and whether attributes are optional or not.(T).Is()
: performs shallow type equality checks, in that the root type is compared, but underlying attribute/element types are not.(T).UsableAs()
: performs type conformance checks. This primarily checks if the target implementsDynamicPsuedoType
in a compatible manner.