diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index c48f3da51f85..6492a5b717f0 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -573,6 +573,11 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) -> self.msg.cannot_use_function_with_type(e.callee.name, "TypedDict", e) elif typ.node.is_newtype: self.msg.cannot_use_function_with_type(e.callee.name, "NewType", e) + if e.callee.name == "issubclass": + for typ in mypy.checker.flatten(e.args[0]): + if isinstance(typ, RefExpr) and isinstance(typ.node, TypeInfo): + if typ.node.is_newtype: + self.msg.cannot_use_function_with_type("issubclass", "NewType", e) self.try_infer_partial_type(e) type_context = None if isinstance(e.callee, LambdaExpr): diff --git a/test-data/unit/check-newtype.test b/test-data/unit/check-newtype.test index 95042d1393ab..aa57440ffa1e 100644 --- a/test-data/unit/check-newtype.test +++ b/test-data/unit/check-newtype.test @@ -369,6 +369,8 @@ d: object if isinstance(d, T): # E: Cannot use isinstance() with NewType type reveal_type(d) # N: Revealed type is "builtins.int" issubclass(object, T) # E: Cannot use issubclass() with NewType type +issubclass(T, object) # E: Cannot use issubclass() with NewType type +issubclass((T,), object) # E: Cannot use issubclass() with NewType type [builtins fixtures/isinstancelist.pyi] [case testInvalidNewTypeCrash]