code: def _type_check(arg, msg):
      
      if arg is None:
          return type(None)
      if isinstance(arg, str):
          arg = _ForwardRef(arg)
      if (
          isinstance(arg, _TypingBase) and type(arg).__name__ == '_ClassVar' or
          not isinstance(arg, (type, _TypingBase)) and not callable(arg)
      ):
          raise TypeError(msg + " Got %.100r." % (arg,))
      # Bare Union etc. are not valid as type arguments
      if (
          type(arg).__name__ in ('_Union', '_Optional') and
          not getattr(arg, '__origin__', None) or
          isinstance(arg, TypingMeta) and arg._gorg in (Generic, _Protocol)
      ):
          raise TypeError("Plain %s is not valid as type argument" % arg)
      return arg
docs: Check that the argument is a type, and return it (internal helper).
  
      As a special case, accept None and return type(None) instead.
      Also, _TypeAlias instances (e.g. Match, Pattern) are acceptable.
  
      The msg argument is a human-readable error message, e.g.
  
          "Union[arg, ...]: arg should be a type."
  
      We append the repr() of the actual value (truncated to 100 chars).