public static PythonTuple __new__(CodeContext context, [NotNull] PythonType cls) { if (cls == TypeCache.PythonTuple) { return(EMPTY); } else { if (!(cls.CreateInstance(context) is PythonTuple tupObj)) { throw PythonOps.TypeError("{0} is not a subclass of tuple", cls); } return(tupObj); } }
public static object __new__(CodeContext context, [NotNull] PythonType cls, int size) { if (cls == TypeCache.Bytes) { if (size < 0) { throw PythonOps.ValueError("negative count"); } return(new Bytes(new byte[size])); } else { return(cls.CreateInstance(context, __new__(context, TypeCache.Bytes, size))); } }
public static FrozenSetCollection __new__(CodeContext /*!*/ context, PythonType cls, object set) { if (cls == TypeCache.FrozenSet) { return(Make(set)); } else { object res = cls.CreateInstance(context, set); if (res is FrozenSetCollection fs) { return(fs); } throw PythonOps.TypeError("{0} is not a subclass of frozenset", res); } }
public static object __new__(CodeContext context, [NotNull] PythonType cls, [NotNull] ExtensibleString @string) { if (cls == TypeCache.Bytes) { if (TryInvokeBytesOperator(context, @string, out Bytes? res)) { return(res); } else { throw PythonOps.TypeError("string argument without an encoding"); } } else { return(cls.CreateInstance(context, __new__(context, TypeCache.Bytes, @string))); } }
public static FrozenSetCollection __new__(CodeContext context, object cls) { if (cls == TypeCache.FrozenSet) { return(EMPTY); } else { PythonType dt = cls as PythonType; object res = dt.CreateInstance(context); FrozenSetCollection fs = res as FrozenSetCollection; if (fs == null) { throw PythonOps.TypeError("{0} is not a subclass of frozenset", res); } return(fs); } }
public static PythonModule /*!*/ __new__(CodeContext /*!*/ context, PythonType /*!*/ cls, params object[] /*!*/ args\u00F8) { PythonModule res; if (cls == TypeCache.Module) { res = new PythonModule(); } else if (cls.IsSubclassOf(TypeCache.Module)) { res = (PythonModule)cls.CreateInstance(context); } else { throw PythonOps.TypeError("{0} is not a subtype of module", cls.Name); } return(res); }
public static object __new__(CodeContext context, [NotNull] PythonType cls, [NotNull] Extensible <int> size) { if (cls == TypeCache.Bytes) { if (TryInvokeBytesOperator(context, size, out Bytes? res)) { return(res); } else { if (size < 0) { throw PythonOps.ValueError("negative count"); } return(new Bytes(new byte[size])); } } else { return(cls.CreateInstance(context, __new__(context, TypeCache.Bytes, size))); } }
public static PythonTuple __new__(CodeContext context, [NotNull] PythonType cls, object?sequence) { if (sequence == null) { return(new PythonTuple(sequence)); // this will throw the proper exception } if (cls == TypeCache.PythonTuple) { if (sequence.GetType() == typeof(PythonTuple)) { return((PythonTuple)sequence); } return(new PythonTuple(sequence)); } else { if (!(cls.CreateInstance(context, sequence) is PythonTuple tupObj)) { throw PythonOps.TypeError("{0} is not a subclass of tuple", cls); } return(tupObj); } }
public static PythonTuple __new__(CodeContext context, PythonType cls, object sequence) { if (sequence == null) { throw PythonOps.TypeError("iteration over a non-sequence"); } if (cls == TypeCache.PythonTuple) { if (sequence.GetType() == typeof(PythonTuple)) { return((PythonTuple)sequence); } return(new PythonTuple(MakeItems(sequence))); } else { if (!(cls.CreateInstance(context, sequence) is PythonTuple tupObj)) { throw PythonOps.TypeError("{0} is not a subclass of tuple", cls); } return(tupObj); } }