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

[stdlib] assertion overloads for List #3372

Closed
wants to merge 1 commit into from

Conversation

jjvraw
Copy link
Contributor

@jjvraw jjvraw commented Aug 9, 2024

Add assert_equal and assert_not_equal overload for List comparisons, a nice-to-have in a few places. Most probably a temporary solution under the current trait system.

@jjvraw jjvraw requested a review from a team as a code owner August 9, 2024 16:31
@jjvraw jjvraw force-pushed the list-assertions branch 2 times, most recently from dabe398 to b2f8597 Compare August 9, 2024 16:32
Comment on lines +31 to +50
def test_assert_messages():
try:
assert_true(False)
except e:
assert_true("test_assertion.mojo:33:20: AssertionError:" in str(e))

try:
assert_false(True)
except e:
assert_true("test_assertion.mojo:38:21: AssertionError:" in str(e))

try:
assert_equal(1, 0)
except e:
assert_true("test_assertion.mojo:43:21: AssertionError:" in str(e))

try:
assert_not_equal(0, 0)
except e:
assert_true("test_assertion.mojo:48:25: AssertionError:" in str(e))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved here to remove dependency on line numbers and future changes

@helehex
Copy link
Contributor

helehex commented Aug 14, 2024

I wish someone would just add the str(List) overload back in. It's easier to track a single TODO on an overload, then to track everywhere in a code base where you weren't unable to use a method because of lacking features.

Copy link
Contributor

@helehex helehex left a comment

Choose a reason for hiding this comment

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

Thanks, I just added something very similar to one of my repos, except for List[List[Int]]. I can see this being useful for the time being. It would simplify tests in /test_list.mojo

One suggestion:
Add a TODO to remove this once we have associated types or more powerful conditional conformance that can infer conformance based on methods which use a inferred parameter to conditionally conform to the trait.

@jjvraw
Copy link
Contributor Author

jjvraw commented Aug 14, 2024

Cool. There are two PRs atm that would benefit from this as well.

Add a TODO to remove...

There's a comment right above the other overloads, will modify that.

repos, except for List[List[Int]]

I actually opened a discussion relevant to this issue, #3357, if you have any opinions :)

@helehex
Copy link
Contributor

helehex commented Aug 14, 2024

Oh yeah, i remember a comment in there somewhere, i guess my PR which removes the need for the other overloads hasn't gotten merged yet.

@JoeLoser
Copy link
Collaborator

!sync

@modularbot modularbot added the imported-internally Signals that a given pull request has been imported internally. label Sep 15, 2024
@modularbot
Copy link
Collaborator

✅🟣 This contribution has been merged 🟣✅

Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the nightly branch during the next Mojo nightly release, typically within the next 24-48 hours.

We use Copybara to merge external contributions, click here to learn more.

@modularbot modularbot added merged-internally Indicates that this pull request has been merged internally merged-externally Merged externally in public mojo repo labels Sep 19, 2024
@modularbot
Copy link
Collaborator

Landed in 1fad4ad! Thank you for your contribution 🎉

modularbot pushed a commit that referenced this pull request Sep 21, 2024
[External] [stdlib] assertion overloads for `List`

Add `assert_equal` and `assert_not_equal` overload for `List`
comparisons, a nice-to-have in a few places. Most probably a temporary
solution under the current trait system.

Co-authored-by: Joshua James Venter <[email protected]>
Closes #3372
MODULAR_ORIG_COMMIT_REV_ID: 73743fb7a84f578717998c6359ba6c07cd6709ab
@modularbot modularbot closed this Sep 21, 2024
@jjvraw jjvraw deleted the list-assertions branch October 4, 2024 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imported-internally Signals that a given pull request has been imported internally. merged-externally Merged externally in public mojo repo merged-internally Indicates that this pull request has been merged internally
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants