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.
from dataclasses import *
import abc
+import io
import pickle
import inspect
import builtins
import types
+import traceback
import unittest
from unittest.mock import Mock
from typing import ClassVar, Any, List, Union, Tuple, Dict, Generic, TypeVar, Optional, Protocol
with self.assertRaisesRegex(TypeError, 'dataclass type or instance'):
fields(C())
+ def test_clean_traceback_from_fields_exception(self):
+ stdout = io.StringIO()
+ try:
+ fields(object)
+ except TypeError as exc:
+ traceback.print_exception(exc, file=stdout)
+ printed_traceback = stdout.getvalue()
+ self.assertNotIn("AttributeError", printed_traceback)
+ self.assertNotIn("__dataclass_fields__", printed_traceback)
+
def test_helper_asdict(self):
# Basic tests for asdict(), it should return a new dictionary.
@dataclass