private IArgumentSet GetArgSet(int index) { var newArg = new PythonConstant(index, Type.DeclaringModule.Interpreter.GetBuiltinType(BuiltinTypeId.Int)); return(new ArgumentSet(new List <IMember> { newArg }, null, null)); }
private void SpecializeMembers() { var location = new Location(this, default); // TypeVar var fn = PythonFunctionType.Specialize("TypeVar", this, GetMemberDocumentation("TypeVar")); var o = new PythonFunctionOverload(fn.Name, location); // When called, create generic parameter type. For documentation // use original TypeVar declaration so it appear as a tooltip. o.SetReturnValueProvider((interpreter, overload, args) => GenericTypeParameter.FromTypeVar(args, interpreter)); fn.AddOverload(o); _members["TypeVar"] = fn; // NewType fn = PythonFunctionType.Specialize("NewType", this, GetMemberDocumentation("NewType")); o = new PythonFunctionOverload(fn.Name, location); // When called, create generic parameter type. For documentation // use original TypeVar declaration so it appear as a tooltip. o.SetReturnValueProvider((interpreter, overload, args) => CreateTypeAlias(args.Values <IMember>())); fn.AddOverload(o); _members["NewType"] = fn; // Type fn = PythonFunctionType.Specialize("Type", this, GetMemberDocumentation("Type")); o = new PythonFunctionOverload(fn.Name, location); // When called, create generic parameter type. For documentation // use original TypeVar declaration so it appear as a tooltip. o.SetReturnValueProvider((interpreter, overload, args) => { var a = args.Values <IMember>(); return(a.Count == 1 ? a[0] : Interpreter.UnknownType); }); fn.AddOverload(o); _members["Type"] = fn; _members["Iterator"] = new GenericType("Iterator", CreateIteratorType, this); _members["Iterable"] = new GenericType("Iterable", typeArgs => CreateListType("Iterable", BuiltinTypeId.List, typeArgs, false), this); _members["Sequence"] = new GenericType("Sequence", typeArgs => CreateListType("Sequence", BuiltinTypeId.List, typeArgs, false), this); _members["MutableSequence"] = new GenericType("MutableSequence", typeArgs => CreateListType("MutableSequence", BuiltinTypeId.List, typeArgs, true), this); _members["List"] = new GenericType("List", typeArgs => CreateListType("List", BuiltinTypeId.List, typeArgs, true), this); _members["MappingView"] = new GenericType("MappingView", typeArgs => CreateDictionary("MappingView", typeArgs, false), this); _members["KeysView"] = new GenericType("KeysView", CreateKeysViewType, this); _members["ValuesView"] = new GenericType("ValuesView", CreateValuesViewType, this); _members["ItemsView"] = new GenericType("ItemsView", CreateItemsViewType, this); _members["Set"] = new GenericType("Set", typeArgs => CreateListType("Set", BuiltinTypeId.Set, typeArgs, true), this); _members["MutableSet"] = new GenericType("MutableSet", typeArgs => CreateListType("MutableSet", BuiltinTypeId.Set, typeArgs, true), this); _members["FrozenSet"] = new GenericType("FrozenSet", typeArgs => CreateListType("FrozenSet", BuiltinTypeId.Set, typeArgs, false), this); _members["Tuple"] = new GenericType("Tuple", CreateTupleType, this); _members["Mapping"] = new GenericType("Mapping", typeArgs => CreateDictionary("Mapping", typeArgs, false), this); _members["MutableMapping"] = new GenericType("MutableMapping", typeArgs => CreateDictionary("MutableMapping", typeArgs, true), this); _members["Dict"] = new GenericType("Dict", typeArgs => CreateDictionary("Dict", typeArgs, true), this); _members["OrderedDict"] = new GenericType("OrderedDict", typeArgs => CreateDictionary("OrderedDict", typeArgs, true), this); _members["DefaultDict"] = new GenericType("DefaultDict", typeArgs => CreateDictionary("DefaultDict", typeArgs, true), this); _members["Union"] = new GenericType("Union", CreateUnion, this); _members["Counter"] = Specialized.Function("Counter", this, GetMemberDocumentation("Counter"), new PythonInstance(Interpreter.GetBuiltinType(BuiltinTypeId.Int))); _members["SupportsInt"] = Interpreter.GetBuiltinType(BuiltinTypeId.Int); _members["SupportsFloat"] = Interpreter.GetBuiltinType(BuiltinTypeId.Float); _members["SupportsComplex"] = Interpreter.GetBuiltinType(BuiltinTypeId.Complex); _members["SupportsBytes"] = Interpreter.GetBuiltinType(BuiltinTypeId.Bytes); _members["ByteString"] = Interpreter.GetBuiltinType(BuiltinTypeId.Bytes); fn = PythonFunctionType.Specialize("NamedTuple", this, GetMemberDocumentation("NamedTuple")); o = new PythonFunctionOverload(fn.Name, location); o.SetReturnValueProvider((interpreter, overload, args) => CreateNamedTuple(args.Values <IMember>())); fn.AddOverload(o); _members["NamedTuple"] = fn; _members["Any"] = new AnyType(this); // AnyStr var str = Interpreter.GetBuiltinType(BuiltinTypeId.Str); var bytes = Interpreter.GetBuiltinType(BuiltinTypeId.Bytes); var unicode = Interpreter.GetBuiltinType(BuiltinTypeId.Unicode); var anyStrName = new PythonConstant("AnyStr", str); var anyStrArgs = Interpreter.LanguageVersion.Is3x() ? new IMember[] { anyStrName, str, bytes } : new IMember[] { anyStrName, str, unicode }; _members["AnyStr"] = GenericTypeParameter.FromTypeVar(new ArgumentSet(anyStrArgs), this); _members["Optional"] = new GenericType("Optional", CreateOptional, this); _members["Type"] = new GenericType("Type", CreateType, this); _members["Generic"] = new GenericType("Generic", CreateGenericClassParameter, this); }