Check the target of NewType [valid-newtype]

The target of a NewType definition must be a class type. It can’tbe a union type, Any, or various other special types.

You can also get this error if the target has been imported from amodule whose source mypy cannot find, since any such definitions aretreated by mypy as values with Any types. Example:

  1. from typing import NewType
  2.  
  3. # The source for "acme" is not available for mypy
  4. from acme import Entity # type: ignore
  5.  
  6. # Error: Argument 2 to NewType(...) must be subclassable (got "Any") [valid-newtype]
  7. UserEntity = NewType('UserEntity', Entity)

To work around the issue, you can either give mypy access to the sourcesfor acme or create a stub file for the module. See Missing importsfor more information.