Skip to content

Improve Error class#1882

Merged
matthewhegarty merged 3 commits intodjango-import-export:mainfrom
adamchainz:improve_error_class
Jun 19, 2024
Merged

Improve Error class#1882
matthewhegarty merged 3 commits intodjango-import-export:mainfrom
adamchainz:improve_error_class

Conversation

@adamchainz
Copy link
Contributor

@adamchainz adamchainz commented Jun 19, 2024

  1. Lazily compute the traceback string, using traceback.format_exception(). It’s only used in the rare case that "traceback" is in the import_error_display attribute, so we can save that work and memory in the usual case.
  2. Add a nice __repr__, to help debug test failures that make assertions on Error objects. I had a few cases where tests failed with inscrutable messages from pytest like Left contains one more item: <import_export.results.Error object at 0x3173c8690>, and I needed to rerun the test with the debugger to inspect the inner exception.

@adamchainz adamchainz marked this pull request as draft June 19, 2024 10:47
1. Lazily compute the traceback string, using `traceback.format_exception()`. It’s only used in the rare case that `"traceback"` is in the `import_error_display` attribute.
2. Add a nice `__repr__`, to help debug test failures that make assertions on `Error` objects. I had a few cases where tests failed with inscrutable messages from pytest like `Left contains one more item: <import_export.results.Error object at 0x3173c8690>`, and I needed to rerun the test with the debugger to inspect the inner exception.
@adamchainz adamchainz force-pushed the improve_error_class branch from 15b49b2 to c4716a8 Compare June 19, 2024 12:23
@adamchainz adamchainz marked this pull request as ready for review June 19, 2024 12:27
Copy link
Contributor

@matthewhegarty matthewhegarty left a comment

Choose a reason for hiding this comment

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

👍 thanks

@coveralls
Copy link

Coverage Status

coverage: 100.0%. remained the same
when pulling c4716a8 on adamchainz:improve_error_class
into 4fddf0e on django-import-export:main.

@coveralls
Copy link

Coverage Status

coverage: 100.0%. remained the same
when pulling 16136e3 on adamchainz:improve_error_class
into 5595178 on django-import-export:main.

@matthewhegarty matthewhegarty merged commit 7de0ad3 into django-import-export:main Jun 19, 2024
@adamchainz adamchainz deleted the improve_error_class branch June 19, 2024 16:37
Viicos added a commit to Viicos/typeshed that referenced this pull request Jan 19, 2025
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