Skip to content

Commit 75ae23e

Browse files
Added invalid type in error message (#2758)
1 parent ee26847 commit 75ae23e

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

astroid/brain/brain_builtin_inference.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,9 @@ def infer_issubclass(callnode, context: InferenceContext | None = None):
769769
except (InferenceError, StopIteration) as exc:
770770
raise UseInferenceDefault from exc
771771
if not isinstance(obj_type, nodes.ClassDef):
772-
raise UseInferenceDefault("TypeError: arg 1 must be class")
772+
raise UseInferenceDefault(
773+
f"TypeError: arg 1 must be class, not {type(obj_type)!r}"
774+
)
773775

774776
# The right hand argument is the class(es) that the given
775777
# object is to be checked against.

astroid/brain/brain_namedtuple_enum.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ def _check_namedtuple_attributes(typename, attributes, rename=False):
280280
# <snippet>
281281
for name in (typename, *attributes):
282282
if not isinstance(name, str):
283-
raise AstroidTypeError("Type names and field names must be strings")
283+
raise AstroidTypeError(
284+
f"Type names and field names must be strings, not {type(name)!r}"
285+
)
284286
if not name.isidentifier():
285287
raise AstroidValueError(
286288
"Type names and field names must be valid" + f"identifiers: {name!r}"

astroid/helpers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ def _object_type_is_subclass(
129129
# issubclass(object, (1, type)) raises TypeError
130130
for klass in class_seq:
131131
if isinstance(klass, util.UninferableBase):
132-
raise AstroidTypeError("arg 2 must be a type or tuple of types")
132+
raise AstroidTypeError(
133+
f"arg 2 must be a type or tuple of types, not {type(klass)!r}"
134+
)
133135

134136
for obj_subclass in obj_type.mro():
135137
if obj_subclass == klass:
@@ -164,7 +166,7 @@ def object_issubclass(
164166
or its type's mro doesn't work
165167
"""
166168
if not isinstance(node, nodes.ClassDef):
167-
raise TypeError(f"{node} needs to be a ClassDef node")
169+
raise TypeError(f"{node} needs to be a ClassDef node, not {type(node)!r}")
168170
return _object_type_is_subclass(node, class_or_seq, context=context)
169171

170172

astroid/protocols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ def _determine_starred_iteration_lookups(
809809

810810
if not isinstance(target, nodes.Tuple):
811811
raise InferenceError(
812-
"Could not make sense of this, the target must be a tuple",
812+
f"Could not make sense of this, the target must be a tuple, not {type(target)!r}",
813813
context=context,
814814
)
815815

0 commit comments

Comments
 (0)