Skip to content

Conversation

@davidhewitt
Copy link
Member

As discussed in #5472 (comment), this improves the clarity of the failure in .cast() operations.

cc @Icxolu @orlp

Copy link
Contributor

@LilyFirefly LilyFirefly left a comment

Choose a reason for hiding this comment

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

The main change here looks good to me. I did spot a confusing test, but tidying that up isn't a blocker.

assert_eq!(
err.to_string(),
"'NoneType' object cannot be cast as 'int | NoneType'"
"'NoneType' object is not an instance of 'int | NoneType'"
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is weird. Is it important that we have NoneType twice, or would it be clearer to use, say, int | str? Because NoneType object (i.e. None) not being an instance of NoneType is at best very confusing, if not outright wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, good point. I wonder if in general we should consider special casing None in the error message too? e.g. 'None' is not an instance of instead of 'NoneType' object is not an instance of

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds nice to have.

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.

4 participants