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

Improve reporting from __iter__ exceptions #11308

Merged
merged 9 commits into from
Aug 21, 2023

Conversation

reaganjlee
Copy link
Contributor

@reaganjlee reaganjlee commented Aug 11, 2023

Fixes #7966

Previously, the assertion rewrite mechanism would fail to capture raised errors within __iter__ and suggest the error is within __repr__, which this new reporting now fixes.

Comment on lines 135 to 138
except TypeError:
return False
except Exception as e:
raise ValueError(
Copy link
Member

Choose a reason for hiding this comment

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

I think we should probably just replace except TypeError: with except Exception: here - if calling iter(obj) raises an error, it seems reasonable to treat that as "not iterable" rather than a special error case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm I think the error message is helpful if people don't expect it, but I can see that this adds to things to maintain

This reverts commit e938580.

Revert "improve error msg and test"

This reverts commit c0cf822.

Revert "error msg"

This reverts commit ec1053c.

Revert "changelog"

This reverts commit d2dc8a7.

Revert "simplify code / take out user-gen typeerror case"

This reverts commit b9cb87d.
@Zac-HD Zac-HD merged commit 050f402 into pytest-dev:main Aug 21, 2023
@Zac-HD
Copy link
Member

Zac-HD commented Aug 21, 2023

Thanks Reagan!

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.

Failure when trying to call __repr__ because __iter__ is called?
3 participants