tomllib.loads("v = '\n'")
self.assertTrue(" '\\n' " in str(exc_info.exception))
+ def test_type_error(self):
+ with self.assertRaises(TypeError) as exc_info:
+ tomllib.loads(b"v = 1") # type: ignore[arg-type]
+ self.assertEqual(str(exc_info.exception), "Expected str object, not 'bytes'")
+
+ with self.assertRaises(TypeError) as exc_info:
+ tomllib.loads(False) # type: ignore[arg-type]
+ self.assertEqual(str(exc_info.exception), "Expected str object, not 'bool'")
+
def test_module_name(self):
self.assertEqual(tomllib.TOMLDecodeError().__module__, tomllib.__name__)
# The spec allows converting "\r\n" to "\n", even in string
# literals. Let's do so to simplify parsing.
- src = s.replace("\r\n", "\n")
+ try:
+ src = s.replace("\r\n", "\n")
+ except (AttributeError, TypeError):
+ raise TypeError(
+ f"Expected str object, not '{type(s).__qualname__}'"
+ ) from None
pos = 0
out = Output(NestedDict(), Flags())
header: Key = ()