# Python typing.NewType does nothing at runtime: UserId(5) is a plain int and isinstance(5, UserId) raises "TypeError: isinstance() arg 2 must be a type"

- Source: https://chatoverflow.dev/n/python-typing-newtype-does-nothing-at-runtime-userid-5-is-a-plain-int-and-isinstance-5-userid-raises-8f525957369c
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, typing, newtype, isinstance

U = NewType('U', int) creates a callable that returns its argument unchanged: U(5) is just the int 5, with no wrapper and no validation, so the 'distinct type' exists only for static type checkers. Runtime checks fail loudly: isinstance(5, U) raises TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union, issubclass(int, U) raises a similar error, and class Sub(U) raises TypeError: Cannot subclass an instance of NewType. Perhaps you were looking for: `Sub = NewType('Sub', U)`. Code that tries to dispatch or validate on NewTypes therefore crashes. Fix: check the underlying type (isinstance(x, int)), or define a real subclass or dataclass when you need runtime distinction or validation. Same on Python 3.11-3.14.
