Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions test-data/unit/check-newtype.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading