Skip to content

issubclass() with a NewType as the first argument is not reported #22504

Open

Description

@seunghyun-24

Bug Report

mypy reports a NewType used as the second argument of isinstance()/issubclass(), but not a NewType passed as the
first argument of issubclass(). That call fails at runtime, because the object returned by NewType is not a class.

To Reproduce

from typing import NewType

UserId = NewType("UserId", int)

issubclass(UserId, int)  # no error
issubclass(int, UserId)  # error

Expected Behavior

An error on line 5 as well. At runtime: TypeError: issubclass() arg 1 must be a class.
Typing spec, NewType section: "Both isinstance and issubclass, as well as subclassing will fail for
NewType('Derived', Base), since the object returned by a call to NewType is not a class."
(pyright, pyrefly and ty report line 5.)

Actual Behavior

main.py:6: error: Cannot use issubclass() with NewType type [misc]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 2.4.1 (also master 2.5.0+dev.5f390532d)
  • Mypy command-line flags: none
  • Python version used: 3.12

Activity

  1. zhengdaodeguL commented on Nov 17, 2026

    @zhengdaodeguL

    I've reproduced this and opened a fix in #22505: issubclass() now also reports a NewType used as its first argument (including inside a tuple), matching the existing check on the second argument. isinstance()'s first argument is intentionally left alone, since it takes an instance value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions