gh-102947: Improve traceback when calling fields() on a non-dataclass (#102948)

This commit is contained in:
Alex Waygood 2023-03-23 14:17:54 +00:00 committed by GitHub
parent 08254be6c5
commit baf4eb083c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View file

@ -1248,7 +1248,7 @@ def fields(class_or_instance):
try:
fields = getattr(class_or_instance, _FIELDS)
except AttributeError:
raise TypeError('must be called with a dataclass type or instance')
raise TypeError('must be called with a dataclass type or instance') from None
# Exclude pseudo-fields. Note that fields is sorted by insertion
# order, so the order of the tuple is as the fields were defined.