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

Refined ABI type-check on assignment #540

Merged
merged 34 commits into from
Oct 13, 2022
Merged

Conversation

ahangsu
Copy link
Contributor

@ahangsu ahangsu commented Sep 22, 2022

After a few short discussions with @jasonpaulos on 2022/09/21-2022/09/22, we decided to introduce another typecheck mechanism on variable assignment for ABI values.

Such mechanism would benefit following issues and PRs: #530, #531, #537

@ahangsu ahangsu marked this pull request as ready for review September 22, 2022 18:29
pyteal/ast/abi/util_test.py Outdated Show resolved Hide resolved
pyteal/ast/abi/util.py Show resolved Hide resolved
pyteal/ast/abi/util.py Show resolved Hide resolved
@ahangsu ahangsu assigned ahangsu and unassigned ahangsu Sep 30, 2022
@ahangsu ahangsu force-pushed the refined-abi-assignment-type-check branch 2 times, most recently from e9135d5 to 99c5c8e Compare September 30, 2022 17:49
ahangsu and others added 3 commits October 7, 2022 15:47
* Add illustrative testing DSL for type_spec_is_assignable_to

* Use NamedTuple to construct `dataclass`-alike class

* Boundary testcase group guarding

Co-authored-by: Hang Su <[email protected]>
@ahangsu ahangsu force-pushed the refined-abi-assignment-type-check branch from c23f1ba to 4b07317 Compare October 11, 2022 19:03
Copy link
Contributor

@jasonpaulos jasonpaulos left a comment

Choose a reason for hiding this comment

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

Mostly looks good, but I have concerns about NamedTuples

CHANGELOG.md Outdated Show resolved Hide resolved
pyteal/ast/abi/util_test.py Show resolved Hide resolved
pyteal/ast/abi/util.py Show resolved Hide resolved
pyteal/ast/abi/util_test.py Outdated Show resolved Hide resolved
@ahangsu ahangsu self-assigned this Oct 13, 2022
@ahangsu ahangsu removed their assignment Oct 13, 2022
@jasonpaulos
Copy link
Contributor

I have one final reservation. Right now NamedTupleTypeSpec does not override the __eq__ method, meaning this code currently passes:

class Point(abi.NamedTuple):
    x: abi.Field[abi.Uint64]
    y: abi.Field[abi.Uint64]

class AccountRecord(abi.NamedTuple):
    algoBalance: abi.Field[abi.Uint64]
    assetBalance: abi.Field[abi.Uint64]

p = Point()
ar = AccountRecord()

assert p.type_spec() == ar.type_spec()
assert abi.type_spec_is_assignable_to(p.type_spec(), ar.type_spec())

I'd argue having the equals method return true between different NamedTuple subclasses and between a Tuple and a NamedTuple is not what we want.

@ahangsu
Copy link
Contributor Author

ahangsu commented Oct 13, 2022

oh boy 🤦 just pushed to save the NamedTupleTypeSpec equality check

Copy link
Contributor

@michaeldiamant michaeldiamant left a comment

Choose a reason for hiding this comment

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

@ahangsu Looks correct - thanks for addressing the added feedback.

Consider these approval notes:

Copy link
Contributor

@jasonpaulos jasonpaulos left a comment

Choose a reason for hiding this comment

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

This looks good! I only left a small comment about calling out some of the recent changes in the changelog

CHANGELOG.md Show resolved Hide resolved
@ahangsu ahangsu changed the base branch from master to feature/abi-assignment-type-check October 13, 2022 21:04
@ahangsu ahangsu changed the base branch from feature/abi-assignment-type-check to master October 13, 2022 21:13
@ahangsu
Copy link
Contributor Author

ahangsu commented Oct 13, 2022

I just dump everything to master, and get #531 merged ASAP.

@ahangsu ahangsu merged commit 221232a into master Oct 13, 2022
@ahangsu ahangsu deleted the refined-abi-assignment-type-check branch October 13, 2022 21:25
@ahangsu ahangsu mentioned this pull request Oct 24, 2022
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