26 base = typing.get_origin(typevar)
28 return isinstance(value, typevar)
29 arg_types = typing.get_args(typevar)
30 if base == collections.abc.Mapping
or base == typing.Mapping:
31 if not isinstance(value, collections.abc.Mapping):
33 assert len(arg_types) == 2
34 (keytype, valuetype) = arg_types
37 for k, v
in value.items()
39 elif base == collections.abc.Sequence
or base == typing.Sequence:
41 if not isinstance(value, base):
43 if len(arg_types) == 0:
45 assert len(arg_types) == 1
46 arg_type = arg_types[0]
48 elif base == typing.Union:
50 raise TypeError(
"unsupported type variable '" + str(typevar) +
"'")