mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
{Type,Exception}Zoo holds static ref
This commit is contained in:
1 parent
0b01e04271
commit
9db69d628f
81 files changed
+652
-668
No files matched your search
+1
-1
@@ -127,7 +127,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
|
||||
};
|
||||
|
||||
if let Err(exc) = result {
|
||||
if exc.fast_isinstance(&vm.ctx.exceptions.system_exit) {
|
||||
if exc.fast_isinstance(vm.ctx.exceptions.system_exit) {
|
||||
repl.save_history(&repl_history_path).unwrap();
|
||||
return Err(exc);
|
||||
}
|
||||
|
||||
+7
-7
@@ -36,14 +36,14 @@ mod _json {
|
||||
let object_hook = vm.option_if_none(ctx.get_attr("object_hook", vm)?);
|
||||
let object_pairs_hook = vm.option_if_none(ctx.get_attr("object_pairs_hook", vm)?);
|
||||
let parse_float = ctx.get_attr("parse_float", vm)?;
|
||||
let parse_float =
|
||||
if vm.is_none(&parse_float) || parse_float.is(&vm.ctx.types.float_type) {
|
||||
None
|
||||
} else {
|
||||
Some(parse_float)
|
||||
};
|
||||
let parse_float = if vm.is_none(&parse_float) || parse_float.is(vm.ctx.types.float_type)
|
||||
{
|
||||
None
|
||||
} else {
|
||||
Some(parse_float)
|
||||
};
|
||||
let parse_int = ctx.get_attr("parse_int", vm)?;
|
||||
let parse_int = if vm.is_none(&parse_int) || parse_int.is(&vm.ctx.types.int_type) {
|
||||
let parse_int = if vm.is_none(&parse_int) || parse_int.is(vm.ctx.types.int_type) {
|
||||
None
|
||||
} else {
|
||||
Some(parse_int)
|
||||
|
||||
@@ -153,7 +153,7 @@ mod _socket {
|
||||
type CastFrom = libc::c_longlong;
|
||||
|
||||
// should really just be to_index() but test_socket tests the error messages explicitly
|
||||
if obj.fast_isinstance(&vm.ctx.types.float_type) {
|
||||
if obj.fast_isinstance(vm.ctx.types.float_type) {
|
||||
return Err(vm.new_type_error("integer argument expected, got float".to_owned()));
|
||||
}
|
||||
let int = vm
|
||||
|
||||
@@ -22,7 +22,7 @@ type PyAsyncGenRef = PyRef<PyAsyncGen>;
|
||||
|
||||
impl PyPayload for PyAsyncGen {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.async_generator
|
||||
vm.ctx.types.async_generator
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ impl Unconstructible for PyAsyncGen {}
|
||||
pub(crate) struct PyAsyncGenWrappedValue(pub PyObjectRef);
|
||||
impl PyPayload for PyAsyncGenWrappedValue {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.async_generator_wrapped_value
|
||||
vm.ctx.types.async_generator_wrapped_value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ impl PyAsyncGenWrappedValue {
|
||||
fn unbox(ag: &PyAsyncGen, val: PyResult<PyIterReturn>, vm: &VirtualMachine) -> PyResult {
|
||||
let (closed, async_done) = match &val {
|
||||
Ok(PyIterReturn::StopIteration(_)) => (true, true),
|
||||
Err(e) if e.fast_isinstance(&vm.ctx.exceptions.generator_exit) => (true, true),
|
||||
Err(e) if e.fast_isinstance(vm.ctx.exceptions.generator_exit) => (true, true),
|
||||
Err(_) => (false, true),
|
||||
_ => (false, false),
|
||||
};
|
||||
@@ -185,7 +185,7 @@ pub(crate) struct PyAsyncGenASend {
|
||||
|
||||
impl PyPayload for PyAsyncGenASend {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.async_generator_asend
|
||||
vm.ctx.types.async_generator_asend
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ pub(crate) struct PyAsyncGenAThrow {
|
||||
|
||||
impl PyPayload for PyAsyncGenAThrow {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.async_generator_athrow
|
||||
vm.ctx.types.async_generator_athrow
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,8 +398,8 @@ impl PyAsyncGenAThrow {
|
||||
self.ag.running_async.store(false);
|
||||
self.state.store(AwaitableState::Closed);
|
||||
if self.aclose
|
||||
&& (exc.fast_isinstance(&vm.ctx.exceptions.stop_async_iteration)
|
||||
|| exc.fast_isinstance(&vm.ctx.exceptions.generator_exit))
|
||||
&& (exc.fast_isinstance(vm.ctx.exceptions.stop_async_iteration)
|
||||
|| exc.fast_isinstance(vm.ctx.exceptions.generator_exit))
|
||||
{
|
||||
vm.new_stop_iteration(None)
|
||||
} else {
|
||||
@@ -416,7 +416,7 @@ impl IterNext for PyAsyncGenAThrow {
|
||||
}
|
||||
|
||||
pub fn init(ctx: &Context) {
|
||||
PyAsyncGen::extend_class(ctx, &ctx.types.async_generator);
|
||||
PyAsyncGenASend::extend_class(ctx, &ctx.types.async_generator_asend);
|
||||
PyAsyncGenAThrow::extend_class(ctx, &ctx.types.async_generator_athrow);
|
||||
PyAsyncGen::extend_class(ctx, ctx.types.async_generator);
|
||||
PyAsyncGenASend::extend_class(ctx, ctx.types.async_generator_asend);
|
||||
PyAsyncGenAThrow::extend_class(ctx, ctx.types.async_generator_athrow);
|
||||
}
|
||||
+12
-12
@@ -16,7 +16,7 @@ impl ToPyObject for bool {
|
||||
|
||||
impl TryFromBorrowedObject for bool {
|
||||
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &PyObject) -> PyResult<bool> {
|
||||
if obj.fast_isinstance(&vm.ctx.types.int_type) {
|
||||
if obj.fast_isinstance(vm.ctx.types.int_type) {
|
||||
Ok(get_value(obj))
|
||||
} else {
|
||||
Err(vm.new_type_error(format!("Expected type bool, not {}", obj.class().name())))
|
||||
@@ -38,7 +38,7 @@ impl PyObjectRef {
|
||||
// If descriptor returns Error, propagate it further
|
||||
let method = method_or_err?;
|
||||
let bool_obj = vm.invoke(&method, ())?;
|
||||
if !bool_obj.fast_isinstance(&vm.ctx.types.bool_type) {
|
||||
if !bool_obj.fast_isinstance(vm.ctx.types.bool_type) {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"__bool__ should return bool, returned type {}",
|
||||
bool_obj.class().name()
|
||||
@@ -81,7 +81,7 @@ pub struct PyBool;
|
||||
|
||||
impl PyPayload for PyBool {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.bool_type
|
||||
vm.ctx.types.bool_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ impl Constructor for PyBool {
|
||||
type Args = OptionalArg<PyObjectRef>;
|
||||
|
||||
fn py_new(zelf: PyTypeRef, x: Self::Args, vm: &VirtualMachine) -> PyResult {
|
||||
if !zelf.fast_isinstance(&vm.ctx.types.type_type) {
|
||||
if !zelf.fast_isinstance(vm.ctx.types.type_type) {
|
||||
let actual_class = zelf.class();
|
||||
let actual_type = &actual_class.name();
|
||||
return Err(vm.new_type_error(format!(
|
||||
@@ -132,8 +132,8 @@ impl PyBool {
|
||||
#[pymethod(name = "__ror__")]
|
||||
#[pymethod(magic)]
|
||||
fn or(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
||||
if lhs.fast_isinstance(&vm.ctx.types.bool_type)
|
||||
&& rhs.fast_isinstance(&vm.ctx.types.bool_type)
|
||||
if lhs.fast_isinstance(vm.ctx.types.bool_type)
|
||||
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
|
||||
{
|
||||
let lhs = get_value(&lhs);
|
||||
let rhs = get_value(&rhs);
|
||||
@@ -146,8 +146,8 @@ impl PyBool {
|
||||
#[pymethod(name = "__rand__")]
|
||||
#[pymethod(magic)]
|
||||
fn and(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
||||
if lhs.fast_isinstance(&vm.ctx.types.bool_type)
|
||||
&& rhs.fast_isinstance(&vm.ctx.types.bool_type)
|
||||
if lhs.fast_isinstance(vm.ctx.types.bool_type)
|
||||
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
|
||||
{
|
||||
let lhs = get_value(&lhs);
|
||||
let rhs = get_value(&rhs);
|
||||
@@ -160,8 +160,8 @@ impl PyBool {
|
||||
#[pymethod(name = "__rxor__")]
|
||||
#[pymethod(magic)]
|
||||
fn xor(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
||||
if lhs.fast_isinstance(&vm.ctx.types.bool_type)
|
||||
&& rhs.fast_isinstance(&vm.ctx.types.bool_type)
|
||||
if lhs.fast_isinstance(vm.ctx.types.bool_type)
|
||||
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
|
||||
{
|
||||
let lhs = get_value(&lhs);
|
||||
let rhs = get_value(&rhs);
|
||||
@@ -173,11 +173,11 @@ impl PyBool {
|
||||
}
|
||||
|
||||
pub(crate) fn init(context: &Context) {
|
||||
PyBool::extend_class(context, &context.types.bool_type);
|
||||
PyBool::extend_class(context, context.types.bool_type);
|
||||
}
|
||||
|
||||
// pub fn not(vm: &VirtualMachine, obj: &PyObject) -> PyResult<bool> {
|
||||
// if obj.fast_isinstance(&vm.ctx.types.bool_type) {
|
||||
// if obj.fast_isinstance(vm.ctx.types.bool_type) {
|
||||
// let value = get_value(obj);
|
||||
// Ok(!value)
|
||||
// } else {
|
||||
|
||||
@@ -64,7 +64,7 @@ pub struct PyBuiltinFunction {
|
||||
|
||||
impl PyPayload for PyBuiltinFunction {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.builtin_function_or_method_type
|
||||
vm.ctx.types.builtin_function_or_method_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ pub struct PyBuiltinMethod {
|
||||
|
||||
impl PyPayload for PyBuiltinMethod {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.method_descriptor_type
|
||||
vm.ctx.types.method_descriptor_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,6 +254,6 @@ impl PyBuiltinMethod {
|
||||
impl Unconstructible for PyBuiltinMethod {}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PyBuiltinFunction::extend_class(context, &context.types.builtin_function_or_method_type);
|
||||
PyBuiltinMethod::extend_class(context, &context.types.method_descriptor_type);
|
||||
PyBuiltinFunction::extend_class(context, context.types.builtin_function_or_method_type);
|
||||
PyBuiltinMethod::extend_class(context, context.types.method_descriptor_type);
|
||||
}
|
||||
@@ -83,14 +83,14 @@ impl From<Vec<u8>> for PyByteArray {
|
||||
|
||||
impl PyPayload for PyByteArray {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.bytearray_type
|
||||
vm.ctx.types.bytearray_type
|
||||
}
|
||||
}
|
||||
|
||||
/// Fill bytearray class methods dictionary.
|
||||
pub(crate) fn init(context: &Context) {
|
||||
PyByteArray::extend_class(context, &context.types.bytearray_type);
|
||||
PyByteArrayIterator::extend_class(context, &context.types.bytearray_iterator_type);
|
||||
PyByteArray::extend_class(context, context.types.bytearray_type);
|
||||
PyByteArrayIterator::extend_class(context, context.types.bytearray_iterator_type);
|
||||
}
|
||||
|
||||
#[pyimpl(
|
||||
@@ -863,7 +863,7 @@ pub struct PyByteArrayIterator {
|
||||
|
||||
impl PyPayload for PyByteArrayIterator {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.bytearray_iterator_type
|
||||
vm.ctx.types.bytearray_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,13 +75,13 @@ impl AsRef<[u8]> for PyBytesRef {
|
||||
|
||||
impl PyPayload for PyBytes {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.bytes_type
|
||||
vm.ctx.types.bytes_type
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn init(context: &Context) {
|
||||
PyBytes::extend_class(context, &context.types.bytes_type);
|
||||
PyBytesIterator::extend_class(context, &context.types.bytes_iterator_type);
|
||||
PyBytes::extend_class(context, context.types.bytes_type);
|
||||
PyBytesIterator::extend_class(context, context.types.bytes_iterator_type);
|
||||
}
|
||||
|
||||
impl Constructor for PyBytes {
|
||||
@@ -134,7 +134,7 @@ impl PyBytes {
|
||||
|
||||
#[pymethod(magic)]
|
||||
fn bytes(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyRef<Self> {
|
||||
if zelf.is(&vm.ctx.types.bytes_type) {
|
||||
if zelf.is(vm.ctx.types.bytes_type) {
|
||||
zelf
|
||||
} else {
|
||||
PyBytes::from(zelf.inner.clone()).into_ref(vm)
|
||||
@@ -480,7 +480,7 @@ impl PyBytes {
|
||||
#[pymethod(name = "__rmul__")]
|
||||
#[pymethod(magic)]
|
||||
fn mul(zelf: PyRef<Self>, value: isize, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
|
||||
if value == 1 && zelf.class().is(&vm.ctx.types.bytes_type) {
|
||||
if value == 1 && zelf.class().is(vm.ctx.types.bytes_type) {
|
||||
// Special case: when some `bytes` is multiplied by `1`,
|
||||
// nothing really happens, we need to return an object itself
|
||||
// with the same `id()` to be compatible with CPython.
|
||||
@@ -633,7 +633,7 @@ impl Comparable for PyBytes {
|
||||
) -> PyResult<PyComparisonValue> {
|
||||
Ok(if let Some(res) = op.identical_optimization(zelf, other) {
|
||||
res.into()
|
||||
} else if other.fast_isinstance(&vm.ctx.types.memoryview_type)
|
||||
} else if other.fast_isinstance(vm.ctx.types.memoryview_type)
|
||||
&& op != PyComparisonOp::Eq
|
||||
&& op != PyComparisonOp::Ne
|
||||
{
|
||||
@@ -666,7 +666,7 @@ pub struct PyBytesIterator {
|
||||
|
||||
impl PyPayload for PyBytesIterator {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.bytes_iterator_type
|
||||
vm.ctx.types.bytes_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ impl From<PyObjectRef> for PyClassMethod {
|
||||
|
||||
impl PyPayload for PyClassMethod {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.classmethod_type
|
||||
vm.ctx.types.classmethod_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,5 +96,5 @@ impl PyClassMethod {
|
||||
}
|
||||
|
||||
pub(crate) fn init(context: &Context) {
|
||||
PyClassMethod::extend_class(context, &context.types.classmethod_type);
|
||||
PyClassMethod::extend_class(context, context.types.classmethod_type);
|
||||
}
|
||||
@@ -153,7 +153,7 @@ impl fmt::Debug for PyCode {
|
||||
|
||||
impl PyPayload for PyCode {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.code_type
|
||||
vm.ctx.types.code_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,5 +246,5 @@ impl ToPyObject for bytecode::CodeObject {
|
||||
}
|
||||
|
||||
pub fn init(ctx: &Context) {
|
||||
PyRef::<PyCode>::extend_class(ctx, &ctx.types.code_type);
|
||||
PyRef::<PyCode>::extend_class(ctx, ctx.types.code_type);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ pub struct PyComplex {
|
||||
|
||||
impl PyPayload for PyComplex {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.complex_type
|
||||
vm.ctx.types.complex_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ impl PyObjectRef {
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PyComplex::extend_class(context, &context.types.complex_type);
|
||||
PyComplex::extend_class(context, context.types.complex_type);
|
||||
}
|
||||
|
||||
fn to_op_complex(value: &PyObject, vm: &VirtualMachine) -> PyResult<Option<Complex64>> {
|
||||
@@ -121,7 +121,7 @@ impl Constructor for PyComplex {
|
||||
let (real, real_was_complex) = match args.real {
|
||||
OptionalArg::Missing => (Complex64::new(0.0, 0.0), false),
|
||||
OptionalArg::Present(val) => {
|
||||
let val = if cls.is(&vm.ctx.types.complex_type) && imag_missing {
|
||||
let val = if cls.is(vm.ctx.types.complex_type) && imag_missing {
|
||||
match val.downcast_exact::<PyComplex>(vm) {
|
||||
Ok(c) => {
|
||||
return Ok(c.into());
|
||||
@@ -162,7 +162,7 @@ impl Constructor for PyComplex {
|
||||
OptionalArg::Present(obj) => {
|
||||
if let Some(c) = obj.try_complex(vm)? {
|
||||
c
|
||||
} else if obj.class().fast_issubclass(&vm.ctx.types.str_type) {
|
||||
} else if obj.class().fast_issubclass(vm.ctx.types.str_type) {
|
||||
return Err(
|
||||
vm.new_type_error("complex() second arg can't be a string".to_owned())
|
||||
);
|
||||
@@ -207,7 +207,7 @@ impl PyComplex {
|
||||
impl PyComplex {
|
||||
#[pymethod(magic)]
|
||||
fn complex(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyRef<PyComplex> {
|
||||
if zelf.is(&vm.ctx.types.complex_type) {
|
||||
if zelf.is(vm.ctx.types.complex_type) {
|
||||
zelf
|
||||
} else {
|
||||
PyComplex::from(zelf.value).into_ref(vm)
|
||||
|
||||
@@ -18,7 +18,7 @@ pub struct PyCoroutine {
|
||||
|
||||
impl PyPayload for PyCoroutine {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.coroutine_type
|
||||
vm.ctx.types.coroutine_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ pub struct PyCoroutineWrapper {
|
||||
|
||||
impl PyPayload for PyCoroutineWrapper {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.coroutine_wrapper_type
|
||||
vm.ctx.types.coroutine_wrapper_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,6 +153,6 @@ impl IterNext for PyCoroutineWrapper {
|
||||
}
|
||||
|
||||
pub fn init(ctx: &Context) {
|
||||
PyCoroutine::extend_class(ctx, &ctx.types.coroutine_type);
|
||||
PyCoroutineWrapper::extend_class(ctx, &ctx.types.coroutine_wrapper_type);
|
||||
PyCoroutine::extend_class(ctx, ctx.types.coroutine_type);
|
||||
PyCoroutineWrapper::extend_class(ctx, ctx.types.coroutine_wrapper_type);
|
||||
}
|
||||
+17
-20
@@ -54,7 +54,7 @@ impl fmt::Debug for PyDict {
|
||||
|
||||
impl PyPayload for PyDict {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.dict_type
|
||||
vm.ctx.types.dict_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,7 +519,7 @@ impl Iterable for PyDict {
|
||||
impl Py<PyDict> {
|
||||
#[inline]
|
||||
fn exact_dict(&self, vm: &VirtualMachine) -> bool {
|
||||
self.class().is(&vm.ctx.types.dict_type)
|
||||
self.class().is(vm.ctx.types.dict_type)
|
||||
}
|
||||
|
||||
fn missing_opt<K: DictKey + ?Sized>(
|
||||
@@ -569,7 +569,7 @@ impl Py<PyDict> {
|
||||
} else {
|
||||
match self.as_object().get_item(key, vm) {
|
||||
Ok(value) => Ok(Some(value)),
|
||||
Err(e) if e.fast_isinstance(&vm.ctx.exceptions.key_error) => {
|
||||
Err(e) if e.fast_isinstance(vm.ctx.exceptions.key_error) => {
|
||||
self.missing_opt(key, vm)
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
@@ -750,7 +750,7 @@ macro_rules! dict_view {
|
||||
|
||||
impl PyPayload for $name {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.$class
|
||||
vm.ctx.types.$class
|
||||
}
|
||||
}
|
||||
|
||||
@@ -763,7 +763,7 @@ macro_rules! dict_view {
|
||||
|
||||
impl PyPayload for $iter_name {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.$iter_class
|
||||
vm.ctx.types.$iter_class
|
||||
}
|
||||
}
|
||||
|
||||
@@ -836,7 +836,7 @@ macro_rules! dict_view {
|
||||
|
||||
impl PyPayload for $reverse_iter_name {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.$reverse_iter_class
|
||||
vm.ctx.types.$reverse_iter_class
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1012,7 +1012,7 @@ trait ViewSetOps: DictView {
|
||||
zelf.dict(),
|
||||
dictview.dict(),
|
||||
op,
|
||||
!zelf.class().is(&vm.ctx.types.dict_keys_type),
|
||||
!zelf.class().is(vm.ctx.types.dict_keys_type),
|
||||
vm,
|
||||
)
|
||||
}
|
||||
@@ -1146,17 +1146,14 @@ impl PyDictValues {
|
||||
}
|
||||
|
||||
pub(crate) fn init(context: &Context) {
|
||||
PyDict::extend_class(context, &context.types.dict_type);
|
||||
PyDictKeys::extend_class(context, &context.types.dict_keys_type);
|
||||
PyDictKeyIterator::extend_class(context, &context.types.dict_keyiterator_type);
|
||||
PyDictReverseKeyIterator::extend_class(context, &context.types.dict_reversekeyiterator_type);
|
||||
PyDictValues::extend_class(context, &context.types.dict_values_type);
|
||||
PyDictValueIterator::extend_class(context, &context.types.dict_valueiterator_type);
|
||||
PyDictReverseValueIterator::extend_class(
|
||||
context,
|
||||
&context.types.dict_reversevalueiterator_type,
|
||||
);
|
||||
PyDictItems::extend_class(context, &context.types.dict_items_type);
|
||||
PyDictItemIterator::extend_class(context, &context.types.dict_itemiterator_type);
|
||||
PyDictReverseItemIterator::extend_class(context, &context.types.dict_reverseitemiterator_type);
|
||||
PyDict::extend_class(context, context.types.dict_type);
|
||||
PyDictKeys::extend_class(context, context.types.dict_keys_type);
|
||||
PyDictKeyIterator::extend_class(context, context.types.dict_keyiterator_type);
|
||||
PyDictReverseKeyIterator::extend_class(context, context.types.dict_reversekeyiterator_type);
|
||||
PyDictValues::extend_class(context, context.types.dict_values_type);
|
||||
PyDictValueIterator::extend_class(context, context.types.dict_valueiterator_type);
|
||||
PyDictReverseValueIterator::extend_class(context, context.types.dict_reversevalueiterator_type);
|
||||
PyDictItems::extend_class(context, context.types.dict_items_type);
|
||||
PyDictItemIterator::extend_class(context, context.types.dict_itemiterator_type);
|
||||
PyDictReverseItemIterator::extend_class(context, context.types.dict_reverseitemiterator_type);
|
||||
}
|
||||
@@ -20,7 +20,7 @@ pub struct PyEnumerate {
|
||||
|
||||
impl PyPayload for PyEnumerate {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.enumerate_type
|
||||
vm.ctx.types.enumerate_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ pub struct PyReverseSequenceIterator {
|
||||
|
||||
impl PyPayload for PyReverseSequenceIterator {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.reverse_iter_type
|
||||
vm.ctx.types.reverse_iter_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +133,6 @@ impl IterNext for PyReverseSequenceIterator {
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PyEnumerate::extend_class(context, &context.types.enumerate_type);
|
||||
PyReverseSequenceIterator::extend_class(context, &context.types.reverse_iter_type);
|
||||
PyEnumerate::extend_class(context, context.types.enumerate_type);
|
||||
PyReverseSequenceIterator::extend_class(context, context.types.reverse_iter_type);
|
||||
}
|
||||
@@ -19,7 +19,7 @@ pub struct PyFilter {
|
||||
|
||||
impl PyPayload for PyFilter {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.filter_type
|
||||
vm.ctx.types.filter_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,5 +74,5 @@ impl IterNext for PyFilter {
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PyFilter::extend_class(context, &context.types.filter_type);
|
||||
PyFilter::extend_class(context, context.types.filter_type);
|
||||
}
|
||||
@@ -34,7 +34,7 @@ impl PyFloat {
|
||||
|
||||
impl PyPayload for PyFloat {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.float_type
|
||||
vm.ctx.types.float_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ impl Constructor for PyFloat {
|
||||
let float_val = match arg {
|
||||
OptionalArg::Missing => 0.0,
|
||||
OptionalArg::Present(val) => {
|
||||
let val = if cls.is(&vm.ctx.types.float_type) {
|
||||
let val = if cls.is(vm.ctx.types.float_type) {
|
||||
match val.downcast_exact::<PyFloat>(vm) {
|
||||
Ok(f) => return Ok(f.into()),
|
||||
Err(val) => val,
|
||||
@@ -567,5 +567,5 @@ pub(crate) fn get_value(obj: &PyObject) -> f64 {
|
||||
|
||||
#[rustfmt::skip] // to avoid line splitting
|
||||
pub fn init(context: &Context) {
|
||||
PyFloat::extend_class(context, &context.types.float_type);
|
||||
PyFloat::extend_class(context, context.types.float_type);
|
||||
}
|
||||
@@ -11,7 +11,7 @@ use crate::{
|
||||
};
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
FrameRef::extend_class(context, &context.types.frame_type);
|
||||
FrameRef::extend_class(context, context.types.frame_type);
|
||||
}
|
||||
|
||||
#[pyimpl(with(Constructor, PyRef))]
|
||||
|
||||
@@ -323,7 +323,7 @@ impl PyFunction {
|
||||
|
||||
impl PyPayload for PyFunction {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.function_type
|
||||
vm.ctx.types.function_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,7 +548,7 @@ impl PyBoundMethod {
|
||||
fn qualname(&self, vm: &VirtualMachine) -> PyResult {
|
||||
if self
|
||||
.function
|
||||
.fast_isinstance(&vm.ctx.types.builtin_function_or_method_type)
|
||||
.fast_isinstance(vm.ctx.types.builtin_function_or_method_type)
|
||||
{
|
||||
// Special case: we work with `__new__`, which is not really a method.
|
||||
// It is a function, so its `__qualname__` is just `__new__`.
|
||||
@@ -569,7 +569,7 @@ impl PyBoundMethod {
|
||||
|
||||
impl PyPayload for PyBoundMethod {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.bound_method_type
|
||||
vm.ctx.types.bound_method_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -582,7 +582,7 @@ pub(crate) type PyCellRef = PyRef<PyCell>;
|
||||
|
||||
impl PyPayload for PyCell {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.cell_type
|
||||
vm.ctx.types.cell_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -627,7 +627,7 @@ impl PyCell {
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PyFunction::extend_class(context, &context.types.function_type);
|
||||
PyBoundMethod::extend_class(context, &context.types.bound_method_type);
|
||||
PyCell::extend_class(context, &context.types.cell_type);
|
||||
PyFunction::extend_class(context, context.types.function_type);
|
||||
PyBoundMethod::extend_class(context, context.types.bound_method_type);
|
||||
PyCell::extend_class(context, context.types.cell_type);
|
||||
}
|
||||
@@ -44,11 +44,11 @@ pub fn new_jit_error(msg: String, vm: &VirtualMachine) -> PyBaseExceptionRef {
|
||||
|
||||
fn get_jit_arg_type(dict: &PyDictRef, name: &str, vm: &VirtualMachine) -> PyResult<JitType> {
|
||||
if let Some(value) = dict.get_item_opt(name, vm)? {
|
||||
if value.is(&vm.ctx.types.int_type) {
|
||||
if value.is(vm.ctx.types.int_type) {
|
||||
Ok(JitType::Int)
|
||||
} else if value.is(&vm.ctx.types.float_type) {
|
||||
} else if value.is(vm.ctx.types.float_type) {
|
||||
Ok(JitType::Float)
|
||||
} else if value.is(&vm.ctx.types.bool_type) {
|
||||
} else if value.is(vm.ctx.types.bool_type) {
|
||||
Ok(JitType::Bool)
|
||||
} else {
|
||||
Err(new_jit_error(
|
||||
@@ -112,14 +112,14 @@ pub fn get_jit_arg_types(
|
||||
fn get_jit_value(vm: &VirtualMachine, obj: &PyObject) -> Result<AbiValue, ArgsError> {
|
||||
// This does exact type checks as subclasses of int/float can't be passed to jitted functions
|
||||
let cls = obj.class();
|
||||
if cls.is(&vm.ctx.types.int_type) {
|
||||
if cls.is(vm.ctx.types.int_type) {
|
||||
int::get_value(obj)
|
||||
.to_i64()
|
||||
.map(AbiValue::Int)
|
||||
.ok_or(ArgsError::IntOverflow)
|
||||
} else if cls.is(&vm.ctx.types.float_type) {
|
||||
} else if cls.is(vm.ctx.types.float_type) {
|
||||
Ok(AbiValue::Float(float::get_value(obj)))
|
||||
} else if cls.is(&vm.ctx.types.bool_type) {
|
||||
} else if cls.is(vm.ctx.types.bool_type) {
|
||||
Ok(AbiValue::Bool(bool_::get_value(obj)))
|
||||
} else {
|
||||
Err(ArgsError::NonJitType)
|
||||
|
||||
@@ -21,7 +21,7 @@ pub struct PyGenerator {
|
||||
|
||||
impl PyPayload for PyGenerator {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.generator_type
|
||||
vm.ctx.types.generator_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,5 +106,5 @@ impl IterNext for PyGenerator {
|
||||
}
|
||||
|
||||
pub fn init(ctx: &Context) {
|
||||
PyGenerator::extend_class(ctx, &ctx.types.generator_type);
|
||||
PyGenerator::extend_class(ctx, ctx.types.generator_type);
|
||||
}
|
||||
@@ -37,7 +37,7 @@ impl fmt::Debug for PyGenericAlias {
|
||||
|
||||
impl PyPayload for PyGenericAlias {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.generic_alias_type
|
||||
vm.ctx.types.generic_alias_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,8 +327,8 @@ impl Callable for PyGenericAlias {
|
||||
fn call(zelf: &crate::Py<Self>, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
|
||||
PyType::call(&zelf.origin, args, vm).map(|obj| {
|
||||
if let Err(exc) = obj.set_attr(identifier!(vm, __orig_class__), zelf.to_owned(), vm) {
|
||||
if !exc.fast_isinstance(&vm.ctx.exceptions.attribute_error)
|
||||
&& !exc.fast_isinstance(&vm.ctx.exceptions.type_error)
|
||||
if !exc.fast_isinstance(vm.ctx.exceptions.attribute_error)
|
||||
&& !exc.fast_isinstance(vm.ctx.exceptions.type_error)
|
||||
{
|
||||
return Err(exc);
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ impl std::fmt::Debug for PyGetSet {
|
||||
|
||||
impl PyPayload for PyGetSet {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.getset_type
|
||||
vm.ctx.types.getset_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,5 +366,5 @@ impl PyGetSet {
|
||||
impl Unconstructible for PyGetSet {}
|
||||
|
||||
pub(crate) fn init(context: &Context) {
|
||||
PyGetSet::extend_class(context, &context.types.getset_type);
|
||||
PyGetSet::extend_class(context, context.types.getset_type);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ where
|
||||
|
||||
impl PyPayload for PyInt {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.int_type
|
||||
vm.ctx.types.int_type
|
||||
}
|
||||
|
||||
fn into_pyobject(self, vm: &VirtualMachine) -> PyObjectRef {
|
||||
@@ -252,7 +252,7 @@ impl Constructor for PyInt {
|
||||
})?;
|
||||
try_int_radix(&val, base, vm)
|
||||
} else {
|
||||
let val = if cls.is(&vm.ctx.types.int_type) {
|
||||
let val = if cls.is(vm.ctx.types.int_type) {
|
||||
match val.downcast_exact::<PyInt>(vm) {
|
||||
Ok(i) => {
|
||||
return Ok(i.to_pyobject(vm));
|
||||
@@ -280,9 +280,9 @@ impl PyInt {
|
||||
where
|
||||
T: Into<BigInt> + ToPrimitive,
|
||||
{
|
||||
if cls.is(&vm.ctx.types.int_type) {
|
||||
if cls.is(vm.ctx.types.int_type) {
|
||||
Ok(vm.ctx.new_int(value))
|
||||
} else if cls.is(&vm.ctx.types.bool_type) {
|
||||
} else if cls.is(vm.ctx.types.bool_type) {
|
||||
Ok(vm.ctx.new_bool(!value.into().eq(&BigInt::zero())))
|
||||
} else {
|
||||
PyInt::from(value).into_ref_with_type(vm, cls)
|
||||
@@ -690,7 +690,7 @@ impl PyInt {
|
||||
|
||||
#[inline]
|
||||
fn clone_if_subclass(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyRef<Self> {
|
||||
if zelf.class().is(&vm.ctx.types.int_type) {
|
||||
if zelf.class().is(vm.ctx.types.int_type) {
|
||||
return zelf;
|
||||
}
|
||||
|
||||
@@ -986,7 +986,7 @@ pub(crate) fn try_int(obj: &PyObject, vm: &VirtualMachine) -> PyResult<BigInt> {
|
||||
}
|
||||
|
||||
pub(crate) fn init(context: &Context) {
|
||||
PyInt::extend_class(context, &context.types.int_type);
|
||||
PyInt::extend_class(context, context.types.int_type);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -170,7 +170,7 @@ pub struct PySequenceIterator {
|
||||
|
||||
impl PyPayload for PySequenceIterator {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.iter_type
|
||||
vm.ctx.types.iter_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ pub struct PyCallableIterator {
|
||||
|
||||
impl PyPayload for PyCallableIterator {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.callable_iterator
|
||||
vm.ctx.types.callable_iterator
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,6 +262,6 @@ impl IterNext for PyCallableIterator {
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PySequenceIterator::extend_class(context, &context.types.iter_type);
|
||||
PyCallableIterator::extend_class(context, &context.types.callable_iterator);
|
||||
PySequenceIterator::extend_class(context, context.types.iter_type);
|
||||
PyCallableIterator::extend_class(context, context.types.callable_iterator);
|
||||
}
|
||||
@@ -54,7 +54,7 @@ impl FromIterator<PyObjectRef> for PyList {
|
||||
|
||||
impl PyPayload for PyList {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.list_type
|
||||
vm.ctx.types.list_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,7 +522,7 @@ pub struct PyListIterator {
|
||||
|
||||
impl PyPayload for PyListIterator {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.list_iterator_type
|
||||
vm.ctx.types.list_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ pub struct PyListReverseIterator {
|
||||
|
||||
impl PyPayload for PyListReverseIterator {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.list_reverseiterator_type
|
||||
vm.ctx.types.list_reverseiterator_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -608,6 +608,6 @@ pub fn init(context: &Context) {
|
||||
let list_type = &context.types.list_type;
|
||||
PyList::extend_class(context, list_type);
|
||||
|
||||
PyListIterator::extend_class(context, &context.types.list_iterator_type);
|
||||
PyListReverseIterator::extend_class(context, &context.types.list_reverseiterator_type);
|
||||
PyListIterator::extend_class(context, context.types.list_iterator_type);
|
||||
PyListReverseIterator::extend_class(context, context.types.list_reverseiterator_type);
|
||||
}
|
||||
@@ -21,7 +21,7 @@ pub struct PyMap {
|
||||
|
||||
impl PyPayload for PyMap {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.map_type
|
||||
vm.ctx.types.map_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,5 +73,5 @@ impl IterNext for PyMap {
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PyMap::extend_class(context, &context.types.map_type);
|
||||
PyMap::extend_class(context, context.types.map_type);
|
||||
}
|
||||
@@ -24,7 +24,7 @@ enum MappingProxyInner {
|
||||
|
||||
impl PyPayload for PyMappingProxy {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.mappingproxy_type
|
||||
vm.ctx.types.mappingproxy_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,5 +205,5 @@ impl Iterable for PyMappingProxy {
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PyMappingProxy::extend_class(context, &context.types.mappingproxy_type)
|
||||
PyMappingProxy::extend_class(context, context.types.mappingproxy_type)
|
||||
}
|
||||
@@ -1042,12 +1042,12 @@ impl Hashable for PyMemoryView {
|
||||
|
||||
impl PyPayload for PyMemoryView {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.memoryview_type
|
||||
vm.ctx.types.memoryview_type
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn init(ctx: &Context) {
|
||||
PyMemoryView::extend_class(ctx, &ctx.types.memoryview_type)
|
||||
PyMemoryView::extend_class(ctx, ctx.types.memoryview_type)
|
||||
}
|
||||
|
||||
fn format_unpack(
|
||||
|
||||
@@ -15,7 +15,7 @@ pub struct PyModule {}
|
||||
|
||||
impl PyPayload for PyModule {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.module_type
|
||||
vm.ctx.types.module_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,5 +148,5 @@ impl GetAttr for PyModule {
|
||||
}
|
||||
|
||||
pub(crate) fn init(context: &Context) {
|
||||
PyModule::extend_class(context, &context.types.module_type);
|
||||
PyModule::extend_class(context, context.types.module_type);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ pub struct PyNamespace {}
|
||||
|
||||
impl PyPayload for PyNamespace {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.namespace_type
|
||||
vm.ctx.types.namespace_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ impl PyNamespace {
|
||||
#[pymethod(magic)]
|
||||
fn repr(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult<String> {
|
||||
let o = zelf.as_object();
|
||||
let name = if o.class().is(&vm.ctx.types.namespace_type) {
|
||||
let name = if o.class().is(vm.ctx.types.namespace_type) {
|
||||
"namespace".to_owned()
|
||||
} else {
|
||||
o.class().slot_name()
|
||||
@@ -98,5 +98,5 @@ impl Comparable for PyNamespace {
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PyNamespace::extend_class(context, &context.types.namespace_type);
|
||||
PyNamespace::extend_class(context, context.types.namespace_type);
|
||||
}
|
||||
@@ -21,7 +21,7 @@ pub struct PyBaseObject;
|
||||
|
||||
impl PyPayload for PyBaseObject {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.object_type
|
||||
vm.ctx.types.object_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ impl PyBaseObject {
|
||||
#[pyslot]
|
||||
fn slot_new(cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {
|
||||
// more or less __new__ operator
|
||||
let dict = if cls.is(&vm.ctx.types.object_type) {
|
||||
let dict = if cls.is(vm.ctx.types.object_type) {
|
||||
None
|
||||
} else {
|
||||
Some(vm.ctx.new_dict())
|
||||
@@ -348,7 +348,7 @@ pub fn object_set_dict(obj: PyObjectRef, dict: PyDictRef, vm: &VirtualMachine) -
|
||||
}
|
||||
|
||||
pub fn init(ctx: &Context) {
|
||||
PyBaseObject::extend_class(ctx, &ctx.types.object_type);
|
||||
PyBaseObject::extend_class(ctx, ctx.types.object_type);
|
||||
}
|
||||
|
||||
fn common_reduce(obj: PyObjectRef, proto: usize, vm: &VirtualMachine) -> PyResult {
|
||||
|
||||
@@ -53,7 +53,7 @@ pub struct PyProperty {
|
||||
|
||||
impl PyPayload for PyProperty {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.property_type
|
||||
vm.ctx.types.property_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,11 +256,11 @@ impl Initializer for PyProperty {
|
||||
}
|
||||
|
||||
pub(crate) fn init(context: &Context) {
|
||||
PyProperty::extend_class(context, &context.types.property_type);
|
||||
PyProperty::extend_class(context, context.types.property_type);
|
||||
|
||||
// This is a bit unfortunate, but this instance attribute overlaps with the
|
||||
// class __doc__ string..
|
||||
extend_class!(context, &context.types.property_type, {
|
||||
extend_class!(context, context.types.property_type, {
|
||||
"__doc__" => context.new_getset(
|
||||
"__doc__",
|
||||
context.types.property_type.clone(),
|
||||
|
||||
@@ -76,7 +76,7 @@ pub struct PyRange {
|
||||
|
||||
impl PyPayload for PyRange {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.range_type
|
||||
vm.ctx.types.range_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,9 +174,9 @@ impl PyRange {
|
||||
// }
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PyRange::extend_class(context, &context.types.range_type);
|
||||
PyLongRangeIterator::extend_class(context, &context.types.longrange_iterator_type);
|
||||
PyRangeIterator::extend_class(context, &context.types.range_iterator_type);
|
||||
PyRange::extend_class(context, context.types.range_type);
|
||||
PyLongRangeIterator::extend_class(context, context.types.longrange_iterator_type);
|
||||
PyRangeIterator::extend_class(context, context.types.range_iterator_type);
|
||||
}
|
||||
|
||||
#[pyimpl(with(AsMapping, AsSequence, Hashable, Comparable, Iterable))]
|
||||
@@ -530,7 +530,7 @@ pub struct PyLongRangeIterator {
|
||||
|
||||
impl PyPayload for PyLongRangeIterator {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.longrange_iterator_type
|
||||
vm.ctx.types.longrange_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -595,7 +595,7 @@ pub struct PyRangeIterator {
|
||||
|
||||
impl PyPayload for PyRangeIterator {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.range_iterator_type
|
||||
vm.ctx.types.range_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -73,13 +73,13 @@ impl fmt::Debug for PyFrozenSet {
|
||||
|
||||
impl PyPayload for PySet {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.set_type
|
||||
vm.ctx.types.set_type
|
||||
}
|
||||
}
|
||||
|
||||
impl PyPayload for PyFrozenSet {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.frozenset_type
|
||||
vm.ctx.types.frozenset_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ impl PySetInner {
|
||||
)
|
||||
// If operation raised KeyError, report original set (set.remove)
|
||||
.map_err(|op_err| {
|
||||
if op_err.fast_isinstance(&vm.ctx.exceptions.key_error) {
|
||||
if op_err.fast_isinstance(vm.ctx.exceptions.key_error) {
|
||||
vm.new_key_error(item.to_owned())
|
||||
} else {
|
||||
op_err
|
||||
@@ -715,7 +715,7 @@ impl Constructor for PyFrozenSet {
|
||||
|
||||
fn py_new(cls: PyTypeRef, iterable: Self::Args, vm: &VirtualMachine) -> PyResult {
|
||||
let elements = if let OptionalArg::Present(iterable) = iterable {
|
||||
let iterable = if cls.is(&vm.ctx.types.frozenset_type) {
|
||||
let iterable = if cls.is(vm.ctx.types.frozenset_type) {
|
||||
match iterable.downcast_exact::<Self>(vm) {
|
||||
Ok(fs) => return Ok(fs.into()),
|
||||
Err(iterable) => iterable,
|
||||
@@ -729,7 +729,7 @@ impl Constructor for PyFrozenSet {
|
||||
};
|
||||
|
||||
// Return empty fs if iterable passed is empty and only for exact fs types.
|
||||
if elements.is_empty() && cls.is(&vm.ctx.types.frozenset_type) {
|
||||
if elements.is_empty() && cls.is(vm.ctx.types.frozenset_type) {
|
||||
Ok(vm.ctx.empty_frozenset.clone().into())
|
||||
} else {
|
||||
Self::from_iter(vm, elements)
|
||||
@@ -768,7 +768,7 @@ impl PyFrozenSet {
|
||||
|
||||
#[pymethod]
|
||||
fn copy(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyRef<Self> {
|
||||
if zelf.class().is(&vm.ctx.types.frozenset_type) {
|
||||
if zelf.class().is(vm.ctx.types.frozenset_type) {
|
||||
zelf
|
||||
} else {
|
||||
Self {
|
||||
@@ -953,8 +953,8 @@ struct SetIterable {
|
||||
impl TryFromObject for SetIterable {
|
||||
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
|
||||
let class = obj.class();
|
||||
if class.fast_issubclass(&vm.ctx.types.set_type)
|
||||
|| class.fast_issubclass(&vm.ctx.types.frozenset_type)
|
||||
if class.fast_issubclass(vm.ctx.types.set_type)
|
||||
|| class.fast_issubclass(vm.ctx.types.frozenset_type)
|
||||
{
|
||||
// the class lease needs to be drop to be able to return the object
|
||||
drop(class);
|
||||
@@ -982,7 +982,7 @@ impl fmt::Debug for PySetIterator {
|
||||
|
||||
impl PyPayload for PySetIterator {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.set_iterator_type
|
||||
vm.ctx.types.set_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1038,7 +1038,7 @@ impl IterNext for PySetIterator {
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PySet::extend_class(context, &context.types.set_type);
|
||||
PyFrozenSet::extend_class(context, &context.types.frozenset_type);
|
||||
PySetIterator::extend_class(context, &context.types.set_iterator_type);
|
||||
PySet::extend_class(context, context.types.set_type);
|
||||
PyFrozenSet::extend_class(context, context.types.frozenset_type);
|
||||
PySetIterator::extend_class(context, context.types.set_iterator_type);
|
||||
}
|
||||
@@ -10,7 +10,7 @@ pub struct PyNone;
|
||||
|
||||
impl PyPayload for PyNone {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.none_type
|
||||
vm.ctx.types.none_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ pub struct PyNotImplemented;
|
||||
|
||||
impl PyPayload for PyNotImplemented {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.not_implemented_type
|
||||
vm.ctx.types.not_implemented_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ pub struct PySlice {
|
||||
|
||||
impl PyPayload for PySlice {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.slice_type
|
||||
vm.ctx.types.slice_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ pub struct PyEllipsis;
|
||||
|
||||
impl PyPayload for PyEllipsis {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.ellipsis_type
|
||||
vm.ctx.types.ellipsis_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ impl PyEllipsis {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PySlice::extend_class(context, &context.types.slice_type);
|
||||
PyEllipsis::extend_class(context, &context.ellipsis.class().clone());
|
||||
pub fn init(ctx: &Context) {
|
||||
PySlice::extend_class(ctx, ctx.types.slice_type);
|
||||
PyEllipsis::extend_class(ctx, &ctx.ellipsis.class());
|
||||
}
|
||||
@@ -15,7 +15,7 @@ pub struct PyStaticMethod {
|
||||
|
||||
impl PyPayload for PyStaticMethod {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.staticmethod_type
|
||||
vm.ctx.types.staticmethod_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,5 +88,5 @@ impl Callable for PyStaticMethod {
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PyStaticMethod::extend_class(context, &context.types.staticmethod_type);
|
||||
PyStaticMethod::extend_class(context, context.types.staticmethod_type);
|
||||
}
|
||||
@@ -243,7 +243,7 @@ pub struct PyStrIterator {
|
||||
|
||||
impl PyPayload for PyStrIterator {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.str_iterator_type
|
||||
vm.ctx.types.str_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -523,12 +523,12 @@ impl PyStr {
|
||||
#[pymethod(name = "__rmul__")]
|
||||
#[pymethod(magic)]
|
||||
fn mul(zelf: PyRef<Self>, value: isize, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
|
||||
if value == 0 && zelf.class().is(&vm.ctx.types.str_type) {
|
||||
if value == 0 && zelf.class().is(vm.ctx.types.str_type) {
|
||||
// Special case: when some `str` is multiplied by `0`,
|
||||
// returns the empty `str`.
|
||||
return Ok(vm.ctx.empty_str.clone());
|
||||
}
|
||||
if (value == 1 || zelf.is_empty()) && zelf.class().is(&vm.ctx.types.str_type) {
|
||||
if (value == 1 || zelf.is_empty()) && zelf.class().is(vm.ctx.types.str_type) {
|
||||
// Special case: when some `str` is multiplied by `1` or is the empty `str`,
|
||||
// nothing really happens, we need to return an object itself
|
||||
// with the same `id()` to be compatible with CPython.
|
||||
@@ -1366,7 +1366,7 @@ pub(crate) fn encode_string(
|
||||
|
||||
impl PyPayload for PyStr {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.str_type
|
||||
vm.ctx.types.str_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1426,9 +1426,9 @@ impl FindArgs {
|
||||
}
|
||||
|
||||
pub fn init(ctx: &Context) {
|
||||
PyStr::extend_class(ctx, &ctx.types.str_type);
|
||||
PyStr::extend_class(ctx, ctx.types.str_type);
|
||||
|
||||
PyStrIterator::extend_class(ctx, &ctx.types.str_iterator_type);
|
||||
PyStrIterator::extend_class(ctx, ctx.types.str_iterator_type);
|
||||
}
|
||||
|
||||
impl SliceableSequenceOp for PyStr {
|
||||
|
||||
@@ -20,7 +20,7 @@ pub struct PySuper {
|
||||
|
||||
impl PyPayload for PySuper {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.super_type
|
||||
vm.ctx.types.super_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ impl GetDescriptor for PySuper {
|
||||
return Ok(zelf.into());
|
||||
}
|
||||
let zelf_class = zelf.as_object().class();
|
||||
if zelf_class.is(&vm.ctx.types.super_type) {
|
||||
if zelf_class.is(vm.ctx.types.super_type) {
|
||||
Ok(PySuper::new(zelf.typ.clone(), obj, vm)?.into_pyobject(vm))
|
||||
} else {
|
||||
let obj = vm.unwrap_or_none(zelf.obj.clone().map(|(o, _)| o));
|
||||
|
||||
@@ -14,7 +14,7 @@ pub type PyTracebackRef = PyRef<PyTraceback>;
|
||||
|
||||
impl PyPayload for PyTraceback {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.traceback_type
|
||||
vm.ctx.types.traceback_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ impl PyTracebackRef {
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PyTraceback::extend_class(context, &context.types.traceback_type);
|
||||
PyTraceback::extend_class(context, context.types.traceback_type);
|
||||
}
|
||||
|
||||
impl serde::Serialize for PyTraceback {
|
||||
|
||||
+10
-10
@@ -37,7 +37,7 @@ impl fmt::Debug for PyTuple {
|
||||
|
||||
impl PyPayload for PyTuple {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.tuple_type
|
||||
vm.ctx.types.tuple_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ impl Constructor for PyTuple {
|
||||
|
||||
fn py_new(cls: PyTypeRef, iterable: Self::Args, vm: &VirtualMachine) -> PyResult {
|
||||
let elements = if let OptionalArg::Present(iterable) = iterable {
|
||||
let iterable = if cls.is(&vm.ctx.types.tuple_type) {
|
||||
let iterable = if cls.is(vm.ctx.types.tuple_type) {
|
||||
match iterable.downcast_exact::<Self>(vm) {
|
||||
Ok(tuple) => return Ok(tuple.into()),
|
||||
Err(iterable) => iterable,
|
||||
@@ -107,7 +107,7 @@ impl Constructor for PyTuple {
|
||||
vec![]
|
||||
};
|
||||
// Return empty tuple only for exact tuple types if the iterable is empty.
|
||||
if elements.is_empty() && cls.is(&vm.ctx.types.tuple_type) {
|
||||
if elements.is_empty() && cls.is(vm.ctx.types.tuple_type) {
|
||||
Ok(vm.ctx.empty_tuple.clone().into())
|
||||
} else {
|
||||
Self {
|
||||
@@ -184,9 +184,9 @@ impl PyTuple {
|
||||
vm: &VirtualMachine,
|
||||
) -> PyArithmeticValue<PyRef<Self>> {
|
||||
let added = other.downcast::<Self>().map(|other| {
|
||||
if other.elements.is_empty() && zelf.class().is(&vm.ctx.types.tuple_type) {
|
||||
if other.elements.is_empty() && zelf.class().is(vm.ctx.types.tuple_type) {
|
||||
zelf
|
||||
} else if zelf.elements.is_empty() && other.class().is(&vm.ctx.types.tuple_type) {
|
||||
} else if zelf.elements.is_empty() && other.class().is(vm.ctx.types.tuple_type) {
|
||||
other
|
||||
} else {
|
||||
let elements = zelf
|
||||
@@ -248,7 +248,7 @@ impl PyTuple {
|
||||
fn mul(zelf: PyRef<Self>, value: isize, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
|
||||
Ok(if zelf.elements.is_empty() || value == 0 {
|
||||
vm.ctx.empty_tuple.clone()
|
||||
} else if value == 1 && zelf.class().is(&vm.ctx.types.tuple_type) {
|
||||
} else if value == 1 && zelf.class().is(vm.ctx.types.tuple_type) {
|
||||
// Special case: when some `tuple` is multiplied by `1`,
|
||||
// nothing really happens, we need to return an object itself
|
||||
// with the same `id()` to be compatible with CPython.
|
||||
@@ -331,7 +331,7 @@ impl PyTuple {
|
||||
// the arguments to pass to tuple() is just one tuple - so we'll be doing tuple(tup), which
|
||||
// should just return tup, or tuplesubclass(tup), which'll copy/validate (e.g. for a
|
||||
// structseq)
|
||||
let tup_arg = if zelf.class().is(&vm.ctx.types.tuple_type) {
|
||||
let tup_arg = if zelf.class().is(vm.ctx.types.tuple_type) {
|
||||
zelf
|
||||
} else {
|
||||
PyTuple::new_ref(zelf.elements.clone().into_vec(), &vm.ctx)
|
||||
@@ -436,7 +436,7 @@ pub(crate) struct PyTupleIterator {
|
||||
|
||||
impl PyPayload for PyTupleIterator {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.tuple_iterator_type
|
||||
vm.ctx.types.tuple_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,8 +475,8 @@ impl IterNext for PyTupleIterator {
|
||||
}
|
||||
|
||||
pub(crate) fn init(context: &Context) {
|
||||
PyTuple::extend_class(context, &context.types.tuple_type);
|
||||
PyTupleIterator::extend_class(context, &context.types.tuple_iterator_type);
|
||||
PyTuple::extend_class(context, context.types.tuple_type);
|
||||
PyTupleIterator::extend_class(context, context.types.tuple_iterator_type);
|
||||
}
|
||||
|
||||
pub struct PyTupleTyped<T: TransmuteFromObject> {
|
||||
|
||||
+12
-13
@@ -53,7 +53,7 @@ impl fmt::Debug for PyType {
|
||||
|
||||
impl PyPayload for PyType {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.type_type
|
||||
vm.ctx.types.type_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ impl PyType {
|
||||
.cloned()
|
||||
// We need to exclude this method from going into recursion:
|
||||
.and_then(|found| {
|
||||
if found.fast_isinstance(&vm.ctx.types.getset_type) {
|
||||
if found.fast_isinstance(vm.ctx.types.getset_type) {
|
||||
None
|
||||
} else {
|
||||
Some(found)
|
||||
@@ -359,7 +359,7 @@ impl PyType {
|
||||
.cloned()
|
||||
// We need to exclude this method from going into recursion:
|
||||
.and_then(|found| {
|
||||
if found.fast_isinstance(&vm.ctx.types.getset_type) {
|
||||
if found.fast_isinstance(vm.ctx.types.getset_type) {
|
||||
None
|
||||
} else {
|
||||
Some(found)
|
||||
@@ -418,7 +418,7 @@ impl PyType {
|
||||
fn slot_new(metatype: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
|
||||
vm_trace!("type.__new__ {:?}", args);
|
||||
|
||||
let is_type_type = metatype.is(&vm.ctx.types.type_type);
|
||||
let is_type_type = metatype.is(vm.ctx.types.type_type);
|
||||
if is_type_type && args.args.len() == 1 && args.kwargs.is_empty() {
|
||||
return Ok(args.args[0].class().clone().into());
|
||||
}
|
||||
@@ -484,19 +484,19 @@ impl PyType {
|
||||
|
||||
let mut attributes = dict.to_attributes(vm);
|
||||
if let Some(f) = attributes.get_mut(identifier!(vm, __new__)) {
|
||||
if f.class().is(&vm.ctx.types.function_type) {
|
||||
if f.class().is(vm.ctx.types.function_type) {
|
||||
*f = PyStaticMethod::from(f.clone()).into_pyobject(vm);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(f) = attributes.get_mut(identifier!(vm, __init_subclass__)) {
|
||||
if f.class().is(&vm.ctx.types.function_type) {
|
||||
if f.class().is(vm.ctx.types.function_type) {
|
||||
*f = PyClassMethod::from(f.clone()).into_pyobject(vm);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(f) = attributes.get_mut(identifier!(vm, __class_getitem__)) {
|
||||
if f.class().is(&vm.ctx.types.function_type) {
|
||||
if f.class().is(vm.ctx.types.function_type) {
|
||||
*f = PyClassMethod::from(f.clone()).into_pyobject(vm);
|
||||
}
|
||||
}
|
||||
@@ -741,8 +741,7 @@ impl Callable for PyType {
|
||||
vm_trace!("type_call: {:?}", zelf);
|
||||
let obj = call_slot_new(zelf.to_owned(), zelf.to_owned(), args.clone(), vm)?;
|
||||
|
||||
if (zelf.is(&vm.ctx.types.type_type) && args.kwargs.is_empty())
|
||||
|| !obj.fast_isinstance(zelf)
|
||||
if (zelf.is(vm.ctx.types.type_type) && args.kwargs.is_empty()) || !obj.fast_isinstance(zelf)
|
||||
{
|
||||
return Ok(obj);
|
||||
}
|
||||
@@ -758,7 +757,7 @@ fn find_base_dict_descr(cls: &PyTypeRef, vm: &VirtualMachine) -> Option<PyObject
|
||||
cls.iter_base_chain().skip(1).find_map(|cls| {
|
||||
// TODO: should actually be some translation of:
|
||||
// cls.slot_dictoffset != 0 && !cls.flags.contains(HEAPTYPE)
|
||||
if cls.is(&vm.ctx.types.type_type) {
|
||||
if cls.is(vm.ctx.types.type_type) {
|
||||
cls.get_attr(identifier!(vm, __dict__))
|
||||
} else {
|
||||
None
|
||||
@@ -808,7 +807,7 @@ fn subtype_set_dict(obj: PyObjectRef, value: PyObjectRef, vm: &VirtualMachine) -
|
||||
*/
|
||||
|
||||
pub(crate) fn init(ctx: &Context) {
|
||||
PyType::extend_class(ctx, &ctx.types.type_type);
|
||||
PyType::extend_class(ctx, ctx.types.type_type);
|
||||
}
|
||||
|
||||
pub(crate) fn call_slot_new(
|
||||
@@ -965,8 +964,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_linearise() {
|
||||
let context = Context::genesis();
|
||||
let object = &context.types.object_type;
|
||||
let type_type = &context.types.type_type;
|
||||
let object = context.types.object_type;
|
||||
let type_type = context.types.type_type;
|
||||
|
||||
let a = PyType::new_ref(
|
||||
"A",
|
||||
|
||||
@@ -28,7 +28,7 @@ impl fmt::Debug for PyUnion {
|
||||
|
||||
impl PyPayload for PyUnion {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.union_type
|
||||
vm.ctx.types.union_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,10 +103,10 @@ impl PyUnion {
|
||||
}
|
||||
|
||||
pub fn is_unionable(obj: PyObjectRef, vm: &VirtualMachine) -> bool {
|
||||
obj.class().is(&vm.ctx.types.none_type)
|
||||
|| obj.class().is(&vm.ctx.types.type_type)
|
||||
|| obj.class().is(&vm.ctx.types.generic_alias_type)
|
||||
|| obj.class().is(&vm.ctx.types.union_type)
|
||||
obj.class().is(vm.ctx.types.none_type)
|
||||
|| obj.class().is(vm.ctx.types.type_type)
|
||||
|| obj.class().is(vm.ctx.types.generic_alias_type)
|
||||
|| obj.class().is(vm.ctx.types.union_type)
|
||||
}
|
||||
|
||||
fn is_typevar(obj: &PyObjectRef, vm: &VirtualMachine) -> bool {
|
||||
@@ -175,8 +175,8 @@ fn dedup_and_flatten_args(args: PyTupleRef, vm: &VirtualMachine) -> PyTupleRef {
|
||||
PyTypeRef::try_from_object(vm, arg.clone()),
|
||||
) {
|
||||
(Ok(a), Ok(b))
|
||||
if a.is(&vm.ctx.types.generic_alias_type)
|
||||
&& b.is(&vm.ctx.types.generic_alias_type) =>
|
||||
if a.is(vm.ctx.types.generic_alias_type)
|
||||
&& b.is(vm.ctx.types.generic_alias_type) =>
|
||||
{
|
||||
param
|
||||
.rich_compare_bool(arg, PyComparisonOp::Eq, vm)
|
||||
|
||||
@@ -14,7 +14,7 @@ pub struct PyWeakProxy {
|
||||
|
||||
impl PyPayload for PyWeakProxy {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.weakproxy_type
|
||||
vm.ctx.types.weakproxy_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ impl Constructor for PyWeakProxy {
|
||||
vm.ctx.new_class(
|
||||
None,
|
||||
"__weakproxy",
|
||||
&vm.ctx.types.weakref_type,
|
||||
vm.ctx.types.weakref_type,
|
||||
super::PyWeak::make_slots(),
|
||||
)
|
||||
});
|
||||
@@ -99,5 +99,5 @@ impl SetAttr for PyWeakProxy {
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PyWeakProxy::extend_class(context, &context.types.weakproxy_type);
|
||||
PyWeakProxy::extend_class(context, context.types.weakproxy_type);
|
||||
}
|
||||
@@ -22,7 +22,7 @@ pub struct WeakNewArgs {
|
||||
|
||||
impl PyPayload for PyWeak {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.weakref_type
|
||||
vm.ctx.types.weakref_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,5 +115,5 @@ impl Comparable for PyWeak {
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PyWeak::extend_class(context, &context.types.weakref_type);
|
||||
PyWeak::extend_class(context, context.types.weakref_type);
|
||||
}
|
||||
@@ -18,7 +18,7 @@ pub struct PyZip {
|
||||
|
||||
impl PyPayload for PyZip {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.zip_type
|
||||
vm.ctx.types.zip_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,6 @@ impl IterNext for PyZip {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(context: &Context) {
|
||||
PyZip::extend_class(context, &context.types.zip_type);
|
||||
pub fn init(ctx: &Context) {
|
||||
PyZip::extend_class(ctx, ctx.types.zip_type);
|
||||
}
|
||||
@@ -1213,7 +1213,7 @@ pub fn bytes_from_object(vm: &VirtualMachine, obj: &PyObject) -> PyResult<Vec<u8
|
||||
return Ok(elements);
|
||||
}
|
||||
|
||||
if !obj.fast_isinstance(&vm.ctx.types.str_type) {
|
||||
if !obj.fast_isinstance(vm.ctx.types.str_type) {
|
||||
if let Ok(elements) = vm.map_iterable_object(obj, |x| value_from_object(vm, &x)) {
|
||||
return elements;
|
||||
}
|
||||
|
||||
+6
-6
@@ -448,7 +448,7 @@ impl CFormatSpec {
|
||||
CFormatType::Float(_) => {
|
||||
let type_name = obj.class().name().to_string();
|
||||
let value = ArgIntoFloat::try_from_object(vm, obj).map_err(|e| {
|
||||
if e.fast_isinstance(&vm.ctx.exceptions.type_error) {
|
||||
if e.fast_isinstance(vm.ctx.exceptions.type_error) {
|
||||
// formatfloat in bytesobject.c generates its own specific exception
|
||||
// text in this case, mirror it here.
|
||||
vm.new_type_error(format!("float argument required, not {}", type_name))
|
||||
@@ -690,9 +690,9 @@ impl CFormatBytes {
|
||||
let mut result = vec![];
|
||||
|
||||
let is_mapping = values_obj.class().has_attr(identifier!(vm, __getitem__))
|
||||
&& !values_obj.fast_isinstance(&vm.ctx.types.tuple_type)
|
||||
&& !values_obj.fast_isinstance(&vm.ctx.types.bytes_type)
|
||||
&& !values_obj.fast_isinstance(&vm.ctx.types.bytearray_type);
|
||||
&& !values_obj.fast_isinstance(vm.ctx.types.tuple_type)
|
||||
&& !values_obj.fast_isinstance(vm.ctx.types.bytes_type)
|
||||
&& !values_obj.fast_isinstance(vm.ctx.types.bytearray_type);
|
||||
|
||||
if num_specifiers == 0 {
|
||||
// literal only
|
||||
@@ -842,8 +842,8 @@ impl CFormatString {
|
||||
let mut result = String::new();
|
||||
|
||||
let is_mapping = values_obj.class().has_attr(identifier!(vm, __getitem__))
|
||||
&& !values_obj.fast_isinstance(&vm.ctx.types.tuple_type)
|
||||
&& !values_obj.fast_isinstance(&vm.ctx.types.str_type);
|
||||
&& !values_obj.fast_isinstance(vm.ctx.types.tuple_type)
|
||||
&& !values_obj.fast_isinstance(vm.ctx.types.str_type);
|
||||
|
||||
if num_specifiers == 0 {
|
||||
// literal only
|
||||
|
||||
+9
-9
@@ -359,12 +359,12 @@ fn extract_unicode_error_range(err: &PyObject, vm: &VirtualMachine) -> PyResult<
|
||||
|
||||
#[inline]
|
||||
fn is_decode_err(err: &PyObject, vm: &VirtualMachine) -> bool {
|
||||
err.fast_isinstance(&vm.ctx.exceptions.unicode_decode_error)
|
||||
err.fast_isinstance(vm.ctx.exceptions.unicode_decode_error)
|
||||
}
|
||||
#[inline]
|
||||
fn is_encode_ish_err(err: &PyObject, vm: &VirtualMachine) -> bool {
|
||||
err.fast_isinstance(&vm.ctx.exceptions.unicode_encode_error)
|
||||
|| err.fast_isinstance(&vm.ctx.exceptions.unicode_translate_error)
|
||||
err.fast_isinstance(vm.ctx.exceptions.unicode_encode_error)
|
||||
|| err.fast_isinstance(vm.ctx.exceptions.unicode_translate_error)
|
||||
}
|
||||
|
||||
fn bad_err_type(err: PyObjectRef, vm: &VirtualMachine) -> PyBaseExceptionRef {
|
||||
@@ -393,12 +393,12 @@ fn ignore_errors(err: PyObjectRef, vm: &VirtualMachine) -> PyResult<(PyObjectRef
|
||||
fn replace_errors(err: PyObjectRef, vm: &VirtualMachine) -> PyResult<(String, usize)> {
|
||||
// char::REPLACEMENT_CHARACTER as a str
|
||||
let replacement_char = "\u{FFFD}";
|
||||
let replace = if err.fast_isinstance(&vm.ctx.exceptions.unicode_encode_error) {
|
||||
let replace = if err.fast_isinstance(vm.ctx.exceptions.unicode_encode_error) {
|
||||
"?"
|
||||
} else if err.fast_isinstance(&vm.ctx.exceptions.unicode_decode_error) {
|
||||
} else if err.fast_isinstance(vm.ctx.exceptions.unicode_decode_error) {
|
||||
let range = extract_unicode_error_range(&err, vm)?;
|
||||
return Ok((replacement_char.to_owned(), range.end));
|
||||
} else if err.fast_isinstance(&vm.ctx.exceptions.unicode_translate_error) {
|
||||
} else if err.fast_isinstance(vm.ctx.exceptions.unicode_translate_error) {
|
||||
replacement_char
|
||||
} else {
|
||||
return Err(bad_err_type(err, vm));
|
||||
@@ -456,7 +456,7 @@ fn backslashreplace_errors(err: PyObjectRef, vm: &VirtualMachine) -> PyResult<(S
|
||||
}
|
||||
|
||||
fn namereplace_errors(err: PyObjectRef, vm: &VirtualMachine) -> PyResult<(String, usize)> {
|
||||
if err.fast_isinstance(&vm.ctx.exceptions.unicode_encode_error) {
|
||||
if err.fast_isinstance(vm.ctx.exceptions.unicode_encode_error) {
|
||||
let range = extract_unicode_error_range(&err, vm)?;
|
||||
let s = PyStrRef::try_from_object(vm, err.get_attr("object", vm)?)?;
|
||||
let s_after_start =
|
||||
@@ -550,7 +550,7 @@ fn get_standard_encoding(encoding: &str) -> (usize, StandardEncoding) {
|
||||
}
|
||||
|
||||
fn surrogatepass_errors(err: PyObjectRef, vm: &VirtualMachine) -> PyResult<(String, usize)> {
|
||||
if err.fast_isinstance(&vm.ctx.exceptions.unicode_encode_error) {
|
||||
if err.fast_isinstance(vm.ctx.exceptions.unicode_encode_error) {
|
||||
let range = extract_unicode_error_range(&err, vm)?;
|
||||
let s = PyStrRef::try_from_object(vm, err.get_attr("object", vm)?)?;
|
||||
let s_encoding = PyStrRef::try_from_object(vm, err.get_attr("encoding", vm)?)?;
|
||||
@@ -662,7 +662,7 @@ fn surrogatepass_errors(err: PyObjectRef, vm: &VirtualMachine) -> PyResult<(Stri
|
||||
}
|
||||
|
||||
fn surrogateescape_errors(err: PyObjectRef, vm: &VirtualMachine) -> PyResult<(String, usize)> {
|
||||
if err.fast_isinstance(&vm.ctx.exceptions.unicode_encode_error) {
|
||||
if err.fast_isinstance(vm.ctx.exceptions.unicode_encode_error) {
|
||||
let range = extract_unicode_error_range(&err, vm)?;
|
||||
let s = PyStrRef::try_from_object(vm, err.get_attr("object", vm)?)?;
|
||||
let s_after_start =
|
||||
|
||||
+6
-6
@@ -38,9 +38,9 @@ pub struct Coro {
|
||||
|
||||
fn gen_name(gen: &PyObject, vm: &VirtualMachine) -> &'static str {
|
||||
let typ = gen.class();
|
||||
if typ.is(&vm.ctx.types.coroutine_type) {
|
||||
if typ.is(vm.ctx.types.coroutine_type) {
|
||||
"coroutine"
|
||||
} else if typ.is(&vm.ctx.types.async_generator) {
|
||||
} else if typ.is(vm.ctx.types.async_generator) {
|
||||
"async generator"
|
||||
} else {
|
||||
"generator"
|
||||
@@ -112,13 +112,13 @@ impl Coro {
|
||||
match result {
|
||||
Ok(exec_res) => Ok(exec_res.into_iter_return(vm)),
|
||||
Err(e) => {
|
||||
if e.fast_isinstance(&vm.ctx.exceptions.stop_iteration) {
|
||||
if e.fast_isinstance(vm.ctx.exceptions.stop_iteration) {
|
||||
let err =
|
||||
vm.new_runtime_error(format!("{} raised StopIteration", gen_name(gen, vm)));
|
||||
err.set_cause(Some(e));
|
||||
Err(err)
|
||||
} else if gen.class().is(&vm.ctx.types.async_generator)
|
||||
&& e.fast_isinstance(&vm.ctx.exceptions.stop_async_iteration)
|
||||
} else if gen.class().is(vm.ctx.types.async_generator)
|
||||
&& e.fast_isinstance(vm.ctx.exceptions.stop_async_iteration)
|
||||
{
|
||||
let err = vm
|
||||
.new_runtime_error("async generator raised StopAsyncIteration".to_owned());
|
||||
@@ -194,5 +194,5 @@ impl Coro {
|
||||
}
|
||||
|
||||
pub fn is_gen_exit(exc: &PyBaseExceptionRef, vm: &VirtualMachine) -> bool {
|
||||
exc.fast_isinstance(&vm.ctx.exceptions.generator_exit)
|
||||
exc.fast_isinstance(vm.ctx.exceptions.generator_exit)
|
||||
}
|
||||
@@ -895,7 +895,7 @@ impl DictKey for usize {
|
||||
}
|
||||
|
||||
fn str_exact<'a>(obj: &'a PyObject, vm: &VirtualMachine) -> Option<&'a PyStr> {
|
||||
if obj.class().is(&vm.ctx.types.str_type) {
|
||||
if obj.class().is(vm.ctx.types.str_type) {
|
||||
obj.payload::<PyStr>()
|
||||
} else {
|
||||
None
|
||||
|
||||
+200
-208
@@ -29,7 +29,7 @@ impl std::fmt::Debug for PyBaseException {
|
||||
|
||||
impl PyPayload for PyBaseException {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.exceptions.base_exception_type
|
||||
vm.ctx.exceptions.base_exception_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ impl TryFromObject for ExceptionCtor {
|
||||
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
|
||||
obj.downcast::<PyType>()
|
||||
.and_then(|cls| {
|
||||
if cls.fast_issubclass(&vm.ctx.exceptions.base_exception_type) {
|
||||
if cls.fast_issubclass(vm.ctx.exceptions.base_exception_type) {
|
||||
Ok(Self::Class(cls))
|
||||
} else {
|
||||
Err(cls.into())
|
||||
@@ -320,75 +320,75 @@ impl ExceptionCtor {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ExceptionZoo {
|
||||
pub base_exception_type: PyTypeRef,
|
||||
pub system_exit: PyTypeRef,
|
||||
pub keyboard_interrupt: PyTypeRef,
|
||||
pub generator_exit: PyTypeRef,
|
||||
pub exception_type: PyTypeRef,
|
||||
pub stop_iteration: PyTypeRef,
|
||||
pub stop_async_iteration: PyTypeRef,
|
||||
pub arithmetic_error: PyTypeRef,
|
||||
pub floating_point_error: PyTypeRef,
|
||||
pub overflow_error: PyTypeRef,
|
||||
pub zero_division_error: PyTypeRef,
|
||||
pub assertion_error: PyTypeRef,
|
||||
pub attribute_error: PyTypeRef,
|
||||
pub buffer_error: PyTypeRef,
|
||||
pub eof_error: PyTypeRef,
|
||||
pub import_error: PyTypeRef,
|
||||
pub module_not_found_error: PyTypeRef,
|
||||
pub lookup_error: PyTypeRef,
|
||||
pub index_error: PyTypeRef,
|
||||
pub key_error: PyTypeRef,
|
||||
pub memory_error: PyTypeRef,
|
||||
pub name_error: PyTypeRef,
|
||||
pub unbound_local_error: PyTypeRef,
|
||||
pub os_error: PyTypeRef,
|
||||
pub blocking_io_error: PyTypeRef,
|
||||
pub child_process_error: PyTypeRef,
|
||||
pub connection_error: PyTypeRef,
|
||||
pub broken_pipe_error: PyTypeRef,
|
||||
pub connection_aborted_error: PyTypeRef,
|
||||
pub connection_refused_error: PyTypeRef,
|
||||
pub connection_reset_error: PyTypeRef,
|
||||
pub file_exists_error: PyTypeRef,
|
||||
pub file_not_found_error: PyTypeRef,
|
||||
pub interrupted_error: PyTypeRef,
|
||||
pub is_a_directory_error: PyTypeRef,
|
||||
pub not_a_directory_error: PyTypeRef,
|
||||
pub permission_error: PyTypeRef,
|
||||
pub process_lookup_error: PyTypeRef,
|
||||
pub timeout_error: PyTypeRef,
|
||||
pub reference_error: PyTypeRef,
|
||||
pub runtime_error: PyTypeRef,
|
||||
pub not_implemented_error: PyTypeRef,
|
||||
pub recursion_error: PyTypeRef,
|
||||
pub syntax_error: PyTypeRef,
|
||||
pub indentation_error: PyTypeRef,
|
||||
pub tab_error: PyTypeRef,
|
||||
pub system_error: PyTypeRef,
|
||||
pub type_error: PyTypeRef,
|
||||
pub value_error: PyTypeRef,
|
||||
pub unicode_error: PyTypeRef,
|
||||
pub unicode_decode_error: PyTypeRef,
|
||||
pub unicode_encode_error: PyTypeRef,
|
||||
pub unicode_translate_error: PyTypeRef,
|
||||
pub base_exception_type: &'static PyTypeRef,
|
||||
pub system_exit: &'static PyTypeRef,
|
||||
pub keyboard_interrupt: &'static PyTypeRef,
|
||||
pub generator_exit: &'static PyTypeRef,
|
||||
pub exception_type: &'static PyTypeRef,
|
||||
pub stop_iteration: &'static PyTypeRef,
|
||||
pub stop_async_iteration: &'static PyTypeRef,
|
||||
pub arithmetic_error: &'static PyTypeRef,
|
||||
pub floating_point_error: &'static PyTypeRef,
|
||||
pub overflow_error: &'static PyTypeRef,
|
||||
pub zero_division_error: &'static PyTypeRef,
|
||||
pub assertion_error: &'static PyTypeRef,
|
||||
pub attribute_error: &'static PyTypeRef,
|
||||
pub buffer_error: &'static PyTypeRef,
|
||||
pub eof_error: &'static PyTypeRef,
|
||||
pub import_error: &'static PyTypeRef,
|
||||
pub module_not_found_error: &'static PyTypeRef,
|
||||
pub lookup_error: &'static PyTypeRef,
|
||||
pub index_error: &'static PyTypeRef,
|
||||
pub key_error: &'static PyTypeRef,
|
||||
pub memory_error: &'static PyTypeRef,
|
||||
pub name_error: &'static PyTypeRef,
|
||||
pub unbound_local_error: &'static PyTypeRef,
|
||||
pub os_error: &'static PyTypeRef,
|
||||
pub blocking_io_error: &'static PyTypeRef,
|
||||
pub child_process_error: &'static PyTypeRef,
|
||||
pub connection_error: &'static PyTypeRef,
|
||||
pub broken_pipe_error: &'static PyTypeRef,
|
||||
pub connection_aborted_error: &'static PyTypeRef,
|
||||
pub connection_refused_error: &'static PyTypeRef,
|
||||
pub connection_reset_error: &'static PyTypeRef,
|
||||
pub file_exists_error: &'static PyTypeRef,
|
||||
pub file_not_found_error: &'static PyTypeRef,
|
||||
pub interrupted_error: &'static PyTypeRef,
|
||||
pub is_a_directory_error: &'static PyTypeRef,
|
||||
pub not_a_directory_error: &'static PyTypeRef,
|
||||
pub permission_error: &'static PyTypeRef,
|
||||
pub process_lookup_error: &'static PyTypeRef,
|
||||
pub timeout_error: &'static PyTypeRef,
|
||||
pub reference_error: &'static PyTypeRef,
|
||||
pub runtime_error: &'static PyTypeRef,
|
||||
pub not_implemented_error: &'static PyTypeRef,
|
||||
pub recursion_error: &'static PyTypeRef,
|
||||
pub syntax_error: &'static PyTypeRef,
|
||||
pub indentation_error: &'static PyTypeRef,
|
||||
pub tab_error: &'static PyTypeRef,
|
||||
pub system_error: &'static PyTypeRef,
|
||||
pub type_error: &'static PyTypeRef,
|
||||
pub value_error: &'static PyTypeRef,
|
||||
pub unicode_error: &'static PyTypeRef,
|
||||
pub unicode_decode_error: &'static PyTypeRef,
|
||||
pub unicode_encode_error: &'static PyTypeRef,
|
||||
pub unicode_translate_error: &'static PyTypeRef,
|
||||
|
||||
#[cfg(feature = "jit")]
|
||||
pub jit_error: PyTypeRef,
|
||||
pub jit_error: &'static PyTypeRef,
|
||||
|
||||
pub warning: PyTypeRef,
|
||||
pub deprecation_warning: PyTypeRef,
|
||||
pub pending_deprecation_warning: PyTypeRef,
|
||||
pub runtime_warning: PyTypeRef,
|
||||
pub syntax_warning: PyTypeRef,
|
||||
pub user_warning: PyTypeRef,
|
||||
pub future_warning: PyTypeRef,
|
||||
pub import_warning: PyTypeRef,
|
||||
pub unicode_warning: PyTypeRef,
|
||||
pub bytes_warning: PyTypeRef,
|
||||
pub resource_warning: PyTypeRef,
|
||||
pub encoding_warning: PyTypeRef,
|
||||
pub warning: &'static PyTypeRef,
|
||||
pub deprecation_warning: &'static PyTypeRef,
|
||||
pub pending_deprecation_warning: &'static PyTypeRef,
|
||||
pub runtime_warning: &'static PyTypeRef,
|
||||
pub syntax_warning: &'static PyTypeRef,
|
||||
pub user_warning: &'static PyTypeRef,
|
||||
pub future_warning: &'static PyTypeRef,
|
||||
pub import_warning: &'static PyTypeRef,
|
||||
pub unicode_warning: &'static PyTypeRef,
|
||||
pub bytes_warning: &'static PyTypeRef,
|
||||
pub resource_warning: &'static PyTypeRef,
|
||||
pub encoding_warning: &'static PyTypeRef,
|
||||
}
|
||||
|
||||
macro_rules! extend_exception {
|
||||
@@ -534,91 +534,91 @@ impl ExceptionZoo {
|
||||
pub(crate) fn init() -> Self {
|
||||
use self::types::*;
|
||||
|
||||
let base_exception_type = PyBaseException::init_bare_type().clone();
|
||||
let base_exception_type = PyBaseException::init_bare_type();
|
||||
|
||||
// Sorted By Hierarchy then alphabetized.
|
||||
let system_exit = PySystemExit::init_bare_type().clone();
|
||||
let keyboard_interrupt = PyKeyboardInterrupt::init_bare_type().clone();
|
||||
let generator_exit = PyGeneratorExit::init_bare_type().clone();
|
||||
let system_exit = PySystemExit::init_bare_type();
|
||||
let keyboard_interrupt = PyKeyboardInterrupt::init_bare_type();
|
||||
let generator_exit = PyGeneratorExit::init_bare_type();
|
||||
|
||||
let exception_type = PyException::init_bare_type().clone();
|
||||
let stop_iteration = PyStopIteration::init_bare_type().clone();
|
||||
let stop_async_iteration = PyStopAsyncIteration::init_bare_type().clone();
|
||||
let arithmetic_error = PyArithmeticError::init_bare_type().clone();
|
||||
let floating_point_error = PyFloatingPointError::init_bare_type().clone();
|
||||
let overflow_error = PyOverflowError::init_bare_type().clone();
|
||||
let zero_division_error = PyZeroDivisionError::init_bare_type().clone();
|
||||
let exception_type = PyException::init_bare_type();
|
||||
let stop_iteration = PyStopIteration::init_bare_type();
|
||||
let stop_async_iteration = PyStopAsyncIteration::init_bare_type();
|
||||
let arithmetic_error = PyArithmeticError::init_bare_type();
|
||||
let floating_point_error = PyFloatingPointError::init_bare_type();
|
||||
let overflow_error = PyOverflowError::init_bare_type();
|
||||
let zero_division_error = PyZeroDivisionError::init_bare_type();
|
||||
|
||||
let assertion_error = PyAssertionError::init_bare_type().clone();
|
||||
let attribute_error = PyAttributeError::init_bare_type().clone();
|
||||
let buffer_error = PyBufferError::init_bare_type().clone();
|
||||
let eof_error = PyEOFError::init_bare_type().clone();
|
||||
let assertion_error = PyAssertionError::init_bare_type();
|
||||
let attribute_error = PyAttributeError::init_bare_type();
|
||||
let buffer_error = PyBufferError::init_bare_type();
|
||||
let eof_error = PyEOFError::init_bare_type();
|
||||
|
||||
let import_error = PyImportError::init_bare_type().clone();
|
||||
let module_not_found_error = PyModuleNotFoundError::init_bare_type().clone();
|
||||
let import_error = PyImportError::init_bare_type();
|
||||
let module_not_found_error = PyModuleNotFoundError::init_bare_type();
|
||||
|
||||
let lookup_error = PyLookupError::init_bare_type().clone();
|
||||
let index_error = PyIndexError::init_bare_type().clone();
|
||||
let key_error = PyKeyError::init_bare_type().clone();
|
||||
let lookup_error = PyLookupError::init_bare_type();
|
||||
let index_error = PyIndexError::init_bare_type();
|
||||
let key_error = PyKeyError::init_bare_type();
|
||||
|
||||
let memory_error = PyMemoryError::init_bare_type().clone();
|
||||
let memory_error = PyMemoryError::init_bare_type();
|
||||
|
||||
let name_error = PyNameError::init_bare_type().clone();
|
||||
let unbound_local_error = PyUnboundLocalError::init_bare_type().clone();
|
||||
let name_error = PyNameError::init_bare_type();
|
||||
let unbound_local_error = PyUnboundLocalError::init_bare_type();
|
||||
|
||||
// os errors
|
||||
let os_error = PyOSError::init_bare_type().clone();
|
||||
let blocking_io_error = PyBlockingIOError::init_bare_type().clone();
|
||||
let child_process_error = PyChildProcessError::init_bare_type().clone();
|
||||
let os_error = PyOSError::init_bare_type();
|
||||
let blocking_io_error = PyBlockingIOError::init_bare_type();
|
||||
let child_process_error = PyChildProcessError::init_bare_type();
|
||||
|
||||
let connection_error = PyConnectionError::init_bare_type().clone();
|
||||
let broken_pipe_error = PyBrokenPipeError::init_bare_type().clone();
|
||||
let connection_aborted_error = PyConnectionAbortedError::init_bare_type().clone();
|
||||
let connection_refused_error = PyConnectionRefusedError::init_bare_type().clone();
|
||||
let connection_reset_error = PyConnectionResetError::init_bare_type().clone();
|
||||
let connection_error = PyConnectionError::init_bare_type();
|
||||
let broken_pipe_error = PyBrokenPipeError::init_bare_type();
|
||||
let connection_aborted_error = PyConnectionAbortedError::init_bare_type();
|
||||
let connection_refused_error = PyConnectionRefusedError::init_bare_type();
|
||||
let connection_reset_error = PyConnectionResetError::init_bare_type();
|
||||
|
||||
let file_exists_error = PyFileExistsError::init_bare_type().clone();
|
||||
let file_not_found_error = PyFileNotFoundError::init_bare_type().clone();
|
||||
let interrupted_error = PyInterruptedError::init_bare_type().clone();
|
||||
let is_a_directory_error = PyIsADirectoryError::init_bare_type().clone();
|
||||
let not_a_directory_error = PyNotADirectoryError::init_bare_type().clone();
|
||||
let permission_error = PyPermissionError::init_bare_type().clone();
|
||||
let process_lookup_error = PyProcessLookupError::init_bare_type().clone();
|
||||
let timeout_error = PyTimeoutError::init_bare_type().clone();
|
||||
let file_exists_error = PyFileExistsError::init_bare_type();
|
||||
let file_not_found_error = PyFileNotFoundError::init_bare_type();
|
||||
let interrupted_error = PyInterruptedError::init_bare_type();
|
||||
let is_a_directory_error = PyIsADirectoryError::init_bare_type();
|
||||
let not_a_directory_error = PyNotADirectoryError::init_bare_type();
|
||||
let permission_error = PyPermissionError::init_bare_type();
|
||||
let process_lookup_error = PyProcessLookupError::init_bare_type();
|
||||
let timeout_error = PyTimeoutError::init_bare_type();
|
||||
|
||||
let reference_error = PyReferenceError::init_bare_type().clone();
|
||||
let reference_error = PyReferenceError::init_bare_type();
|
||||
|
||||
let runtime_error = PyRuntimeError::init_bare_type().clone();
|
||||
let not_implemented_error = PyNotImplementedError::init_bare_type().clone();
|
||||
let recursion_error = PyRecursionError::init_bare_type().clone();
|
||||
let runtime_error = PyRuntimeError::init_bare_type();
|
||||
let not_implemented_error = PyNotImplementedError::init_bare_type();
|
||||
let recursion_error = PyRecursionError::init_bare_type();
|
||||
|
||||
let syntax_error = PySyntaxError::init_bare_type().clone();
|
||||
let indentation_error = PyIndentationError::init_bare_type().clone();
|
||||
let tab_error = PyTabError::init_bare_type().clone();
|
||||
let syntax_error = PySyntaxError::init_bare_type();
|
||||
let indentation_error = PyIndentationError::init_bare_type();
|
||||
let tab_error = PyTabError::init_bare_type();
|
||||
|
||||
let system_error = PySystemError::init_bare_type().clone();
|
||||
let type_error = PyTypeError::init_bare_type().clone();
|
||||
let value_error = PyValueError::init_bare_type().clone();
|
||||
let unicode_error = PyUnicodeError::init_bare_type().clone();
|
||||
let unicode_decode_error = PyUnicodeDecodeError::init_bare_type().clone();
|
||||
let unicode_encode_error = PyUnicodeEncodeError::init_bare_type().clone();
|
||||
let unicode_translate_error = PyUnicodeTranslateError::init_bare_type().clone();
|
||||
let system_error = PySystemError::init_bare_type();
|
||||
let type_error = PyTypeError::init_bare_type();
|
||||
let value_error = PyValueError::init_bare_type();
|
||||
let unicode_error = PyUnicodeError::init_bare_type();
|
||||
let unicode_decode_error = PyUnicodeDecodeError::init_bare_type();
|
||||
let unicode_encode_error = PyUnicodeEncodeError::init_bare_type();
|
||||
let unicode_translate_error = PyUnicodeTranslateError::init_bare_type();
|
||||
|
||||
#[cfg(feature = "jit")]
|
||||
let jit_error = PyJitError::init_bare_type().clone();
|
||||
let jit_error = PyJitError::init_bare_type();
|
||||
|
||||
let warning = PyWarning::init_bare_type().clone();
|
||||
let deprecation_warning = PyDeprecationWarning::init_bare_type().clone();
|
||||
let pending_deprecation_warning = PyPendingDeprecationWarning::init_bare_type().clone();
|
||||
let runtime_warning = PyRuntimeWarning::init_bare_type().clone();
|
||||
let syntax_warning = PySyntaxWarning::init_bare_type().clone();
|
||||
let user_warning = PyUserWarning::init_bare_type().clone();
|
||||
let future_warning = PyFutureWarning::init_bare_type().clone();
|
||||
let import_warning = PyImportWarning::init_bare_type().clone();
|
||||
let unicode_warning = PyUnicodeWarning::init_bare_type().clone();
|
||||
let bytes_warning = PyBytesWarning::init_bare_type().clone();
|
||||
let resource_warning = PyResourceWarning::init_bare_type().clone();
|
||||
let encoding_warning = PyEncodingWarning::init_bare_type().clone();
|
||||
let warning = PyWarning::init_bare_type();
|
||||
let deprecation_warning = PyDeprecationWarning::init_bare_type();
|
||||
let pending_deprecation_warning = PyPendingDeprecationWarning::init_bare_type();
|
||||
let runtime_warning = PyRuntimeWarning::init_bare_type();
|
||||
let syntax_warning = PySyntaxWarning::init_bare_type();
|
||||
let user_warning = PyUserWarning::init_bare_type();
|
||||
let future_warning = PyFutureWarning::init_bare_type();
|
||||
let import_warning = PyImportWarning::init_bare_type();
|
||||
let unicode_warning = PyUnicodeWarning::init_bare_type();
|
||||
let bytes_warning = PyBytesWarning::init_bare_type();
|
||||
let resource_warning = PyResourceWarning::init_bare_type();
|
||||
let encoding_warning = PyEncodingWarning::init_bare_type();
|
||||
|
||||
Self {
|
||||
base_exception_type,
|
||||
@@ -700,51 +700,51 @@ impl ExceptionZoo {
|
||||
|
||||
let excs = &ctx.exceptions;
|
||||
|
||||
PyBaseException::extend_class(ctx, &excs.base_exception_type);
|
||||
PyBaseException::extend_class(ctx, excs.base_exception_type);
|
||||
|
||||
// Sorted By Hierarchy then alphabetized.
|
||||
extend_exception!(PySystemExit, ctx, &excs.system_exit, {
|
||||
extend_exception!(PySystemExit, ctx, excs.system_exit, {
|
||||
"code" => ctx.new_readonly_getset("code", excs.system_exit.clone(), system_exit_code),
|
||||
});
|
||||
extend_exception!(PyKeyboardInterrupt, ctx, &excs.keyboard_interrupt);
|
||||
extend_exception!(PyGeneratorExit, ctx, &excs.generator_exit);
|
||||
extend_exception!(PyKeyboardInterrupt, ctx, excs.keyboard_interrupt);
|
||||
extend_exception!(PyGeneratorExit, ctx, excs.generator_exit);
|
||||
|
||||
extend_exception!(PyException, ctx, &excs.exception_type);
|
||||
extend_exception!(PyException, ctx, excs.exception_type);
|
||||
|
||||
extend_exception!(PyStopIteration, ctx, &excs.stop_iteration, {
|
||||
extend_exception!(PyStopIteration, ctx, excs.stop_iteration, {
|
||||
"value" => ctx.new_readonly_getset("value", excs.stop_iteration.clone(), make_arg_getter(0)),
|
||||
});
|
||||
extend_exception!(PyStopAsyncIteration, ctx, &excs.stop_async_iteration);
|
||||
extend_exception!(PyStopAsyncIteration, ctx, excs.stop_async_iteration);
|
||||
|
||||
extend_exception!(PyArithmeticError, ctx, &excs.arithmetic_error);
|
||||
extend_exception!(PyFloatingPointError, ctx, &excs.floating_point_error);
|
||||
extend_exception!(PyOverflowError, ctx, &excs.overflow_error);
|
||||
extend_exception!(PyZeroDivisionError, ctx, &excs.zero_division_error);
|
||||
extend_exception!(PyArithmeticError, ctx, excs.arithmetic_error);
|
||||
extend_exception!(PyFloatingPointError, ctx, excs.floating_point_error);
|
||||
extend_exception!(PyOverflowError, ctx, excs.overflow_error);
|
||||
extend_exception!(PyZeroDivisionError, ctx, excs.zero_division_error);
|
||||
|
||||
extend_exception!(PyAssertionError, ctx, &excs.assertion_error);
|
||||
extend_exception!(PyAttributeError, ctx, &excs.attribute_error, {
|
||||
extend_exception!(PyAssertionError, ctx, excs.assertion_error);
|
||||
extend_exception!(PyAttributeError, ctx, excs.attribute_error, {
|
||||
"name" => ctx.none(),
|
||||
"obj" => ctx.none(),
|
||||
});
|
||||
extend_exception!(PyBufferError, ctx, &excs.buffer_error);
|
||||
extend_exception!(PyEOFError, ctx, &excs.eof_error);
|
||||
extend_exception!(PyBufferError, ctx, excs.buffer_error);
|
||||
extend_exception!(PyEOFError, ctx, excs.eof_error);
|
||||
|
||||
extend_exception!(PyImportError, ctx, &excs.import_error, {
|
||||
extend_exception!(PyImportError, ctx, excs.import_error, {
|
||||
"msg" => ctx.new_readonly_getset("msg", excs.import_error.clone(), make_arg_getter(0)),
|
||||
});
|
||||
extend_exception!(PyModuleNotFoundError, ctx, &excs.module_not_found_error);
|
||||
extend_exception!(PyModuleNotFoundError, ctx, excs.module_not_found_error);
|
||||
|
||||
extend_exception!(PyLookupError, ctx, &excs.lookup_error);
|
||||
extend_exception!(PyIndexError, ctx, &excs.index_error);
|
||||
extend_exception!(PyKeyError, ctx, &excs.key_error, {
|
||||
extend_exception!(PyLookupError, ctx, excs.lookup_error);
|
||||
extend_exception!(PyIndexError, ctx, excs.index_error);
|
||||
extend_exception!(PyKeyError, ctx, excs.key_error, {
|
||||
"__str__" => ctx.new_method("__str__", excs.key_error.clone(), key_error_str),
|
||||
});
|
||||
|
||||
extend_exception!(PyMemoryError, ctx, &excs.memory_error);
|
||||
extend_exception!(PyNameError, ctx, &excs.name_error, {
|
||||
extend_exception!(PyMemoryError, ctx, excs.memory_error);
|
||||
extend_exception!(PyNameError, ctx, excs.name_error, {
|
||||
"name" => ctx.none(),
|
||||
});
|
||||
extend_exception!(PyUnboundLocalError, ctx, &excs.unbound_local_error);
|
||||
extend_exception!(PyUnboundLocalError, ctx, excs.unbound_local_error);
|
||||
|
||||
// os errors:
|
||||
let errno_getter =
|
||||
@@ -752,7 +752,7 @@ impl ExceptionZoo {
|
||||
let args = exc.args();
|
||||
args.get(0).filter(|_| args.len() > 1).cloned()
|
||||
});
|
||||
extend_exception!(PyOSError, ctx, &excs.os_error, {
|
||||
extend_exception!(PyOSError, ctx, excs.os_error, {
|
||||
// POSIX exception code
|
||||
"errno" => errno_getter.clone(),
|
||||
// exception strerror
|
||||
@@ -768,38 +768,30 @@ impl ExceptionZoo {
|
||||
excs.os_error
|
||||
.set_str_attr("winerror", errno_getter.clone(), ctx);
|
||||
|
||||
extend_exception!(PyBlockingIOError, ctx, &excs.blocking_io_error);
|
||||
extend_exception!(PyChildProcessError, ctx, &excs.child_process_error);
|
||||
extend_exception!(PyBlockingIOError, ctx, excs.blocking_io_error);
|
||||
extend_exception!(PyChildProcessError, ctx, excs.child_process_error);
|
||||
|
||||
extend_exception!(PyConnectionError, ctx, &excs.connection_error);
|
||||
extend_exception!(PyBrokenPipeError, ctx, &excs.broken_pipe_error);
|
||||
extend_exception!(
|
||||
PyConnectionAbortedError,
|
||||
ctx,
|
||||
&excs.connection_aborted_error
|
||||
);
|
||||
extend_exception!(
|
||||
PyConnectionRefusedError,
|
||||
ctx,
|
||||
&excs.connection_refused_error
|
||||
);
|
||||
extend_exception!(PyConnectionResetError, ctx, &excs.connection_reset_error);
|
||||
extend_exception!(PyConnectionError, ctx, excs.connection_error);
|
||||
extend_exception!(PyBrokenPipeError, ctx, excs.broken_pipe_error);
|
||||
extend_exception!(PyConnectionAbortedError, ctx, excs.connection_aborted_error);
|
||||
extend_exception!(PyConnectionRefusedError, ctx, excs.connection_refused_error);
|
||||
extend_exception!(PyConnectionResetError, ctx, excs.connection_reset_error);
|
||||
|
||||
extend_exception!(PyFileExistsError, ctx, &excs.file_exists_error);
|
||||
extend_exception!(PyFileNotFoundError, ctx, &excs.file_not_found_error);
|
||||
extend_exception!(PyInterruptedError, ctx, &excs.interrupted_error);
|
||||
extend_exception!(PyIsADirectoryError, ctx, &excs.is_a_directory_error);
|
||||
extend_exception!(PyNotADirectoryError, ctx, &excs.not_a_directory_error);
|
||||
extend_exception!(PyPermissionError, ctx, &excs.permission_error);
|
||||
extend_exception!(PyProcessLookupError, ctx, &excs.process_lookup_error);
|
||||
extend_exception!(PyTimeoutError, ctx, &excs.timeout_error);
|
||||
extend_exception!(PyFileExistsError, ctx, excs.file_exists_error);
|
||||
extend_exception!(PyFileNotFoundError, ctx, excs.file_not_found_error);
|
||||
extend_exception!(PyInterruptedError, ctx, excs.interrupted_error);
|
||||
extend_exception!(PyIsADirectoryError, ctx, excs.is_a_directory_error);
|
||||
extend_exception!(PyNotADirectoryError, ctx, excs.not_a_directory_error);
|
||||
extend_exception!(PyPermissionError, ctx, excs.permission_error);
|
||||
extend_exception!(PyProcessLookupError, ctx, excs.process_lookup_error);
|
||||
extend_exception!(PyTimeoutError, ctx, excs.timeout_error);
|
||||
|
||||
extend_exception!(PyReferenceError, ctx, &excs.reference_error);
|
||||
extend_exception!(PyRuntimeError, ctx, &excs.runtime_error);
|
||||
extend_exception!(PyNotImplementedError, ctx, &excs.not_implemented_error);
|
||||
extend_exception!(PyRecursionError, ctx, &excs.recursion_error);
|
||||
extend_exception!(PyReferenceError, ctx, excs.reference_error);
|
||||
extend_exception!(PyRuntimeError, ctx, excs.runtime_error);
|
||||
extend_exception!(PyNotImplementedError, ctx, excs.not_implemented_error);
|
||||
extend_exception!(PyRecursionError, ctx, excs.recursion_error);
|
||||
|
||||
extend_exception!(PySyntaxError, ctx, &excs.syntax_error, {
|
||||
extend_exception!(PySyntaxError, ctx, excs.syntax_error, {
|
||||
"msg" => ctx.new_readonly_getset("msg", excs.syntax_error.clone(), make_arg_getter(0)),
|
||||
// TODO: members
|
||||
"filename" => ctx.none(),
|
||||
@@ -807,28 +799,28 @@ impl ExceptionZoo {
|
||||
"offset" => ctx.none(),
|
||||
"text" => ctx.none(),
|
||||
});
|
||||
extend_exception!(PyIndentationError, ctx, &excs.indentation_error);
|
||||
extend_exception!(PyTabError, ctx, &excs.tab_error);
|
||||
extend_exception!(PyIndentationError, ctx, excs.indentation_error);
|
||||
extend_exception!(PyTabError, ctx, excs.tab_error);
|
||||
|
||||
extend_exception!(PySystemError, ctx, &excs.system_error);
|
||||
extend_exception!(PyTypeError, ctx, &excs.type_error);
|
||||
extend_exception!(PyValueError, ctx, &excs.value_error);
|
||||
extend_exception!(PyUnicodeError, ctx, &excs.unicode_error);
|
||||
extend_exception!(PyUnicodeDecodeError, ctx, &excs.unicode_decode_error, {
|
||||
extend_exception!(PySystemError, ctx, excs.system_error);
|
||||
extend_exception!(PyTypeError, ctx, excs.type_error);
|
||||
extend_exception!(PyValueError, ctx, excs.value_error);
|
||||
extend_exception!(PyUnicodeError, ctx, excs.unicode_error);
|
||||
extend_exception!(PyUnicodeDecodeError, ctx, excs.unicode_decode_error, {
|
||||
"encoding" => ctx.new_readonly_getset("encoding", excs.unicode_decode_error.clone(), make_arg_getter(0)),
|
||||
"object" => ctx.new_readonly_getset("object", excs.unicode_decode_error.clone(), make_arg_getter(1)),
|
||||
"start" => ctx.new_readonly_getset("start", excs.unicode_decode_error.clone(), make_arg_getter(2)),
|
||||
"end" => ctx.new_readonly_getset("end", excs.unicode_decode_error.clone(), make_arg_getter(3)),
|
||||
"reason" => ctx.new_readonly_getset("reason", excs.unicode_decode_error.clone(), make_arg_getter(4)),
|
||||
});
|
||||
extend_exception!(PyUnicodeEncodeError, ctx, &excs.unicode_encode_error, {
|
||||
extend_exception!(PyUnicodeEncodeError, ctx, excs.unicode_encode_error, {
|
||||
"encoding" => ctx.new_readonly_getset("encoding", excs.unicode_encode_error.clone(), make_arg_getter(0)),
|
||||
"object" => ctx.new_readonly_getset("object", excs.unicode_encode_error.clone(), make_arg_getter(1)),
|
||||
"start" => ctx.new_readonly_getset("start", excs.unicode_encode_error.clone(), make_arg_getter(2), ),
|
||||
"end" => ctx.new_readonly_getset("end", excs.unicode_encode_error.clone(), make_arg_getter(3)),
|
||||
"reason" => ctx.new_readonly_getset("reason", excs.unicode_encode_error.clone(), make_arg_getter(4)),
|
||||
});
|
||||
extend_exception!(PyUnicodeTranslateError, ctx, &excs.unicode_translate_error, {
|
||||
extend_exception!(PyUnicodeTranslateError, ctx, excs.unicode_translate_error, {
|
||||
"encoding" => ctx.new_readonly_getset("encoding", excs.unicode_translate_error.clone(), none_getter),
|
||||
"object" => ctx.new_readonly_getset("object", excs.unicode_translate_error.clone(), make_arg_getter(0)),
|
||||
"start" => ctx.new_readonly_getset("start", excs.unicode_translate_error.clone(), make_arg_getter(1)),
|
||||
@@ -837,24 +829,24 @@ impl ExceptionZoo {
|
||||
});
|
||||
|
||||
#[cfg(feature = "jit")]
|
||||
extend_exception!(PyJitError, ctx, &excs.jit_error);
|
||||
extend_exception!(PyJitError, ctx, excs.jit_error);
|
||||
|
||||
extend_exception!(PyWarning, ctx, &excs.warning);
|
||||
extend_exception!(PyDeprecationWarning, ctx, &excs.deprecation_warning);
|
||||
extend_exception!(PyWarning, ctx, excs.warning);
|
||||
extend_exception!(PyDeprecationWarning, ctx, excs.deprecation_warning);
|
||||
extend_exception!(
|
||||
PyPendingDeprecationWarning,
|
||||
ctx,
|
||||
&excs.pending_deprecation_warning
|
||||
excs.pending_deprecation_warning
|
||||
);
|
||||
extend_exception!(PyRuntimeWarning, ctx, &excs.runtime_warning);
|
||||
extend_exception!(PySyntaxWarning, ctx, &excs.syntax_warning);
|
||||
extend_exception!(PyUserWarning, ctx, &excs.user_warning);
|
||||
extend_exception!(PyFutureWarning, ctx, &excs.future_warning);
|
||||
extend_exception!(PyImportWarning, ctx, &excs.import_warning);
|
||||
extend_exception!(PyUnicodeWarning, ctx, &excs.unicode_warning);
|
||||
extend_exception!(PyBytesWarning, ctx, &excs.bytes_warning);
|
||||
extend_exception!(PyResourceWarning, ctx, &excs.resource_warning);
|
||||
extend_exception!(PyEncodingWarning, ctx, &excs.encoding_warning);
|
||||
extend_exception!(PyRuntimeWarning, ctx, excs.runtime_warning);
|
||||
extend_exception!(PySyntaxWarning, ctx, excs.syntax_warning);
|
||||
extend_exception!(PyUserWarning, ctx, excs.user_warning);
|
||||
extend_exception!(PyFutureWarning, ctx, excs.future_warning);
|
||||
extend_exception!(PyImportWarning, ctx, excs.import_warning);
|
||||
extend_exception!(PyUnicodeWarning, ctx, excs.unicode_warning);
|
||||
extend_exception!(PyBytesWarning, ctx, excs.bytes_warning);
|
||||
extend_exception!(PyResourceWarning, ctx, excs.resource_warning);
|
||||
extend_exception!(PyEncodingWarning, ctx, excs.encoding_warning);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -115,7 +115,7 @@ pub struct Frame {
|
||||
|
||||
impl PyPayload for Frame {
|
||||
fn class(vm: &VirtualMachine) -> &PyTypeRef {
|
||||
&vm.ctx.types.frame_type
|
||||
vm.ctx.types.frame_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ impl FrameRef {
|
||||
for (&k, v) in itertools::zip(&map[..j], &**fastlocals) {
|
||||
match locals.mapping().ass_subscript(k, v.clone(), vm) {
|
||||
Ok(()) => {}
|
||||
Err(e) if e.fast_isinstance(&vm.ctx.exceptions.key_error) => {}
|
||||
Err(e) if e.fast_isinstance(vm.ctx.exceptions.key_error) => {}
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
}
|
||||
@@ -203,7 +203,7 @@ impl FrameRef {
|
||||
} else {
|
||||
match locals.mapping().ass_subscript(k, None, vm) {
|
||||
Ok(()) => {}
|
||||
Err(e) if e.fast_isinstance(&vm.ctx.exceptions.key_error) => {}
|
||||
Err(e) if e.fast_isinstance(vm.ctx.exceptions.key_error) => {}
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
}
|
||||
@@ -404,7 +404,7 @@ impl ExecutingFrame<'_> {
|
||||
return ret.map(ExecutionResult::Yield).or_else(|err| {
|
||||
self.pop_value();
|
||||
self.update_lasti(|i| *i += 1);
|
||||
if err.fast_isinstance(&vm.ctx.exceptions.stop_iteration) {
|
||||
if err.fast_isinstance(vm.ctx.exceptions.stop_iteration) {
|
||||
let val = vm.unwrap_or_none(err.get_arg(0));
|
||||
self.push_value(val);
|
||||
self.run(vm)
|
||||
@@ -561,7 +561,7 @@ impl ExecutingFrame<'_> {
|
||||
|
||||
match res {
|
||||
Ok(()) => {}
|
||||
Err(e) if e.fast_isinstance(&vm.ctx.exceptions.key_error) => {
|
||||
Err(e) if e.fast_isinstance(vm.ctx.exceptions.key_error) => {
|
||||
return Err(vm.new_name_error(
|
||||
format!("name '{}' is not defined", name),
|
||||
name.to_owned(),
|
||||
@@ -575,7 +575,7 @@ impl ExecutingFrame<'_> {
|
||||
let name = self.code.names[*idx as usize];
|
||||
match self.globals.del_item(name, vm) {
|
||||
Ok(()) => {}
|
||||
Err(e) if e.fast_isinstance(&vm.ctx.exceptions.key_error) => {
|
||||
Err(e) if e.fast_isinstance(vm.ctx.exceptions.key_error) => {
|
||||
return Err(vm.new_name_error(
|
||||
format!("name '{}' is not defined", name),
|
||||
name.to_owned(),
|
||||
@@ -905,7 +905,7 @@ impl ExecutingFrame<'_> {
|
||||
bytecode::Instruction::EndAsyncFor => {
|
||||
let exc = self.pop_value();
|
||||
self.pop_value(); // async iterator we were calling __anext__ on
|
||||
if exc.fast_isinstance(&vm.ctx.exceptions.stop_async_iteration) {
|
||||
if exc.fast_isinstance(vm.ctx.exceptions.stop_async_iteration) {
|
||||
vm.take_exception().expect("Should have exception in stack");
|
||||
Ok(None)
|
||||
} else {
|
||||
@@ -1022,7 +1022,7 @@ impl ExecutingFrame<'_> {
|
||||
bytecode::Instruction::UnpackSequence { size } => {
|
||||
let value = self.pop_value();
|
||||
let elements: Vec<_> = value.try_to_value(vm).map_err(|e| {
|
||||
if e.class().is(&vm.ctx.exceptions.type_error) {
|
||||
if e.class().is(vm.ctx.exceptions.type_error) {
|
||||
vm.new_type_error(format!(
|
||||
"cannot unpack non-iterable {} object",
|
||||
value.class().name()
|
||||
|
||||
+1
-1
@@ -203,7 +203,7 @@ pub fn remove_importlib_frames(
|
||||
vm: &VirtualMachine,
|
||||
exc: &PyBaseExceptionRef,
|
||||
) -> PyBaseExceptionRef {
|
||||
let always_trim = exc.fast_isinstance(&vm.ctx.exceptions.import_error);
|
||||
let always_trim = exc.fast_isinstance(vm.ctx.exceptions.import_error);
|
||||
|
||||
if let Some(tb) = exc.traceback() {
|
||||
let trimmed_tb = remove_importlib_frames_inner(vm, Some(tb), always_trim).0;
|
||||
|
||||
@@ -600,7 +600,7 @@ impl PyObject {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let cls_is_weakref = typ.is(&vm.ctx.types.weakref_type);
|
||||
let cls_is_weakref = typ.is(vm.ctx.types.weakref_type);
|
||||
self.weak_ref_list()
|
||||
.map(|wrl| wrl.add(self, typ, cls_is_weakref, callback, dict))
|
||||
.ok_or_else(|| {
|
||||
|
||||
@@ -153,7 +153,7 @@ impl PyIterReturn {
|
||||
pub fn from_pyresult(result: PyResult, vm: &VirtualMachine) -> PyResult<Self> {
|
||||
match result {
|
||||
Ok(obj) => Ok(Self::Return(obj)),
|
||||
Err(err) if err.fast_isinstance(&vm.ctx.exceptions.stop_iteration) => {
|
||||
Err(err) if err.fast_isinstance(vm.ctx.exceptions.stop_iteration) => {
|
||||
let args = err.get_arg(0);
|
||||
Ok(Self::StopIteration(args))
|
||||
}
|
||||
@@ -164,10 +164,10 @@ impl PyIterReturn {
|
||||
pub fn from_getitem_result(result: PyResult, vm: &VirtualMachine) -> PyResult<Self> {
|
||||
match result {
|
||||
Ok(obj) => Ok(Self::Return(obj)),
|
||||
Err(err) if err.fast_isinstance(&vm.ctx.exceptions.index_error) => {
|
||||
Err(err) if err.fast_isinstance(vm.ctx.exceptions.index_error) => {
|
||||
Ok(Self::StopIteration(None))
|
||||
}
|
||||
Err(err) if err.fast_isinstance(&vm.ctx.exceptions.stop_iteration) => {
|
||||
Err(err) if err.fast_isinstance(vm.ctx.exceptions.stop_iteration) => {
|
||||
let args = err.get_arg(0);
|
||||
Ok(Self::StopIteration(args))
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ impl PyMapping<'_> {
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
let meth_output = vm.call_method(self.obj, method_name.as_str(), ())?;
|
||||
if meth_output.is(&vm.ctx.types.list_type) {
|
||||
if meth_output.is(vm.ctx.types.list_type) {
|
||||
return Ok(meth_output);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ impl PyObjectRef {
|
||||
}
|
||||
|
||||
pub fn bytes(self, vm: &VirtualMachine) -> PyResult {
|
||||
let bytes_type = &vm.ctx.types.bytes_type;
|
||||
let bytes_type = vm.ctx.types.bytes_type;
|
||||
match self.downcast_exact::<PyInt>(vm) {
|
||||
Ok(int) => Err(vm.new_downcast_type_error(bytes_type, &int)),
|
||||
Err(obj) => PyBytes::py_new(
|
||||
@@ -159,7 +159,7 @@ impl PyObject {
|
||||
dict.set_item(&*attr_name, value, vm)?;
|
||||
} else {
|
||||
dict.del_item(&*attr_name, vm).map_err(|e| {
|
||||
if e.fast_isinstance(&vm.ctx.exceptions.key_error) {
|
||||
if e.fast_isinstance(vm.ctx.exceptions.key_error) {
|
||||
vm.new_attribute_error(format!(
|
||||
"'{}' object has no attribute '{}'",
|
||||
self.class().name(),
|
||||
@@ -327,7 +327,7 @@ impl PyObject {
|
||||
|
||||
// Container of the virtual machine state:
|
||||
pub fn str(&self, vm: &VirtualMachine) -> PyResult<PyStrRef> {
|
||||
if self.class().is(&vm.ctx.types.str_type) {
|
||||
if self.class().is(vm.ctx.types.str_type) {
|
||||
Ok(self.to_owned().downcast().unwrap())
|
||||
} else {
|
||||
let s = vm.call_special_method(self.to_owned(), identifier!(vm, __str__), ())?;
|
||||
@@ -345,7 +345,7 @@ impl PyObject {
|
||||
.get_attr(identifier!(vm, __bases__), vm)
|
||||
.map_err(|e| {
|
||||
// Only mask AttributeErrors.
|
||||
if e.class().is(&vm.ctx.exceptions.attribute_error) {
|
||||
if e.class().is(vm.ctx.exceptions.attribute_error) {
|
||||
vm.new_type_error(msg())
|
||||
} else {
|
||||
e
|
||||
@@ -412,7 +412,7 @@ impl PyObject {
|
||||
/// Determines if `self` is a subclass of `cls`, either directly, indirectly or virtually
|
||||
/// via the __subclasscheck__ magic method.
|
||||
pub fn is_subclass(&self, cls: &PyObject, vm: &VirtualMachine) -> PyResult<bool> {
|
||||
if cls.class().is(&vm.ctx.types.type_type) {
|
||||
if cls.class().is(vm.ctx.types.type_type) {
|
||||
if self.is(cls) {
|
||||
return Ok(true);
|
||||
}
|
||||
@@ -483,7 +483,7 @@ impl PyObject {
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
if cls.class().is(&vm.ctx.types.type_type) {
|
||||
if cls.class().is(vm.ctx.types.type_type) {
|
||||
return self.abstract_isinstance(cls, vm);
|
||||
}
|
||||
|
||||
@@ -545,8 +545,8 @@ impl PyObject {
|
||||
let i = needle.key_as_isize(vm)?;
|
||||
seq.get_item(i, vm)
|
||||
} else {
|
||||
if self.class().fast_issubclass(&vm.ctx.types.type_type) {
|
||||
if self.is(&vm.ctx.types.type_type) {
|
||||
if self.class().fast_issubclass(vm.ctx.types.type_type) {
|
||||
if self.is(vm.ctx.types.type_type) {
|
||||
return PyGenericAlias::new(self.class().clone(), needle, vm).to_pyresult(vm);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ impl PySequence<'_> {
|
||||
pub fn methods_cow(&self, vm: &VirtualMachine) -> &Cow<'static, PySequenceMethods> {
|
||||
self.methods.get_or_init(|| {
|
||||
let cls = self.obj.class();
|
||||
if !cls.is(&vm.ctx.types.dict_type) {
|
||||
if !cls.is(vm.ctx.types.dict_type) {
|
||||
if let Some(f) = cls.mro_find_map(|x| x.slots.as_sequence.load()) {
|
||||
return f(self.obj, vm);
|
||||
}
|
||||
|
||||
+4
-4
@@ -64,11 +64,11 @@ impl<'s> serde::Serialize for PyObjectSerializer<'s> {
|
||||
};
|
||||
if let Some(s) = self.pyobject.payload::<PyStr>() {
|
||||
serializer.serialize_str(s.as_ref())
|
||||
} else if self.pyobject.fast_isinstance(&self.vm.ctx.types.float_type) {
|
||||
} else if self.pyobject.fast_isinstance(self.vm.ctx.types.float_type) {
|
||||
serializer.serialize_f64(float::get_value(self.pyobject))
|
||||
} else if self.pyobject.fast_isinstance(&self.vm.ctx.types.bool_type) {
|
||||
} else if self.pyobject.fast_isinstance(self.vm.ctx.types.bool_type) {
|
||||
serializer.serialize_bool(bool_::get_value(self.pyobject))
|
||||
} else if self.pyobject.fast_isinstance(&self.vm.ctx.types.int_type) {
|
||||
} else if self.pyobject.fast_isinstance(self.vm.ctx.types.int_type) {
|
||||
let v = int::get_value(self.pyobject);
|
||||
let int_too_large = || serde::ser::Error::custom("int too large to serialize");
|
||||
// TODO: serialize BigInt when it does not fit into i64
|
||||
@@ -84,7 +84,7 @@ impl<'s> serde::Serialize for PyObjectSerializer<'s> {
|
||||
serialize_seq_elements(serializer, &list.borrow_vec())
|
||||
} else if let Some(tuple) = self.pyobject.payload_if_subclass::<PyTuple>(self.vm) {
|
||||
serialize_seq_elements(serializer, tuple)
|
||||
} else if self.pyobject.fast_isinstance(&self.vm.ctx.types.dict_type) {
|
||||
} else if self.pyobject.fast_isinstance(self.vm.ctx.types.dict_type) {
|
||||
let dict: PyDictRef = self.pyobject.to_owned().downcast().unwrap();
|
||||
let pairs: Vec<_> = dict.into_iter().collect();
|
||||
let mut map = serializer.serialize_map(Some(pairs.len()))?;
|
||||
|
||||
@@ -213,7 +213,7 @@ impl Node for ast::Constant {
|
||||
let constant = match_class!(match object {
|
||||
ref i @ builtins::int::PyInt => {
|
||||
let value = i.as_bigint();
|
||||
if object.class().is(&vm.ctx.types.bool_type) {
|
||||
if object.class().is(vm.ctx.types.bool_type) {
|
||||
ast::Constant::Bool(!value.is_zero())
|
||||
} else {
|
||||
ast::Constant::Int(value.clone())
|
||||
|
||||
@@ -37,7 +37,7 @@ mod atexit {
|
||||
let funcs: Vec<_> = std::mem::take(&mut *vm.state.atexit_funcs.lock());
|
||||
for (func, args) in funcs.into_iter().rev() {
|
||||
if let Err(e) = vm.invoke(&func, args) {
|
||||
let exit = e.fast_isinstance(&vm.ctx.exceptions.system_exit);
|
||||
let exit = e.fast_isinstance(vm.ctx.exceptions.system_exit);
|
||||
vm.run_unraisable(e, Some("Error in atexit._run_exitfuncs".to_owned()), func);
|
||||
if exit {
|
||||
break;
|
||||
|
||||
@@ -820,7 +820,7 @@ mod builtins {
|
||||
let mut new_bases: Option<Vec<PyObjectRef>> = None;
|
||||
let bases = PyTuple::new_ref(bases.into_vec(), &vm.ctx);
|
||||
for (i, base) in bases.iter().enumerate() {
|
||||
if base.fast_isinstance(&vm.ctx.types.type_type) {
|
||||
if base.fast_isinstance(vm.ctx.types.type_type) {
|
||||
if let Some(bases) = &mut new_bases {
|
||||
bases.push(base.clone());
|
||||
}
|
||||
|
||||
+7
-7
@@ -121,7 +121,7 @@ mod _io {
|
||||
recursion::ReprGuard,
|
||||
types::{Constructor, DefaultConstructor, Destructor, Initializer, IterNext, Iterable},
|
||||
vm::VirtualMachine,
|
||||
AsObject, Context, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
TryFromBorrowedObject, TryFromObject,
|
||||
};
|
||||
use bstr::ByteSlice;
|
||||
@@ -1343,8 +1343,8 @@ mod _io {
|
||||
let name = match obj.to_owned().get_attr("name", vm) {
|
||||
Ok(name) => Some(name),
|
||||
Err(e)
|
||||
if e.fast_isinstance(&vm.ctx.exceptions.attribute_error)
|
||||
|| e.fast_isinstance(&vm.ctx.exceptions.value_error) =>
|
||||
if e.fast_isinstance(vm.ctx.exceptions.attribute_error)
|
||||
|| e.fast_isinstance(vm.ctx.exceptions.value_error) =>
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -3561,7 +3561,7 @@ mod _io {
|
||||
|
||||
// Construct a FileIO (subclass of RawIOBase)
|
||||
// This is subsequently consumed by a Buffered Class.
|
||||
let file_io_class = {
|
||||
let file_io_class: &Py<PyType> = {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))] {
|
||||
Some(super::fileio::FileIO::static_type())
|
||||
@@ -3569,8 +3569,8 @@ mod _io {
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
let file_io_class: &PyTypeRef = file_io_class.ok_or_else(|| {
|
||||
}
|
||||
.ok_or_else(|| {
|
||||
new_unsupported_operation(
|
||||
vm,
|
||||
"Couldn't get FileIO, io.open likely isn't supported on your platform".to_owned(),
|
||||
@@ -3865,7 +3865,7 @@ mod fileio {
|
||||
zelf.mode.store(mode);
|
||||
let fd = if let Some(opener) = args.opener {
|
||||
let fd = vm.invoke(&opener, (name.clone(), flags))?;
|
||||
if !fd.fast_isinstance(&vm.ctx.types.int_type) {
|
||||
if !fd.fast_isinstance(vm.ctx.types.int_type) {
|
||||
return Err(vm.new_type_error("expected integer from opener".to_owned()));
|
||||
}
|
||||
let fd = i32::try_from_object(vm, fd)?;
|
||||
|
||||
@@ -729,7 +729,7 @@ mod decl {
|
||||
name: &'static str,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<usize> {
|
||||
let is_int = obj.fast_isinstance(&vm.ctx.types.int_type);
|
||||
let is_int = obj.fast_isinstance(vm.ctx.types.int_type);
|
||||
if is_int {
|
||||
let value = int::get_value(&obj).to_usize();
|
||||
if let Some(value) = value {
|
||||
|
||||
@@ -60,7 +60,7 @@ mod decl {
|
||||
fn _dumps(value: PyObjectRef, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
|
||||
let r = match_class!(match value {
|
||||
pyint @ PyInt => {
|
||||
if pyint.class().is(&vm.ctx.types.bool_type) {
|
||||
if pyint.class().is(vm.ctx.types.bool_type) {
|
||||
let (_, mut bool_bytes) = pyint.as_bigint().to_bytes_le();
|
||||
bool_bytes.push(BOOL_BYTE);
|
||||
bool_bytes
|
||||
|
||||
@@ -198,7 +198,7 @@ mod _operator {
|
||||
fn concat(a: PyObjectRef, b: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
// Best attempt at checking that a is sequence-like.
|
||||
if !a.class().has_attr(identifier!(vm, __getitem__))
|
||||
|| a.fast_isinstance(&vm.ctx.types.dict_type)
|
||||
|| a.fast_isinstance(vm.ctx.types.dict_type)
|
||||
{
|
||||
return Err(
|
||||
vm.new_type_error(format!("{} object can't be concatenated", a.class().name()))
|
||||
@@ -272,7 +272,7 @@ mod _operator {
|
||||
fn length_hint(obj: PyObjectRef, default: OptionalArg, vm: &VirtualMachine) -> PyResult<usize> {
|
||||
let default: usize = default
|
||||
.map(|v| {
|
||||
if !v.fast_isinstance(&vm.ctx.types.int_type) {
|
||||
if !v.fast_isinstance(vm.ctx.types.int_type) {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"'{}' type cannot be interpreted as an integer",
|
||||
v.class().name()
|
||||
@@ -303,7 +303,7 @@ mod _operator {
|
||||
fn iconcat(a: PyObjectRef, b: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
// Best attempt at checking that a is sequence-like.
|
||||
if !a.class().has_attr(identifier!(vm, __getitem__))
|
||||
|| a.fast_isinstance(&vm.ctx.types.dict_type)
|
||||
|| a.fast_isinstance(vm.ctx.types.dict_type)
|
||||
{
|
||||
return Err(
|
||||
vm.new_type_error(format!("{} object can't be concatenated", a.class().name()))
|
||||
|
||||
+2
-2
@@ -832,8 +832,8 @@ pub(super) mod _os {
|
||||
let name = match zelf.get_attr("name", vm) {
|
||||
Ok(name) => Some(name),
|
||||
Err(e)
|
||||
if e.fast_isinstance(&vm.ctx.exceptions.attribute_error)
|
||||
|| e.fast_isinstance(&vm.ctx.exceptions.value_error) =>
|
||||
if e.fast_isinstance(vm.ctx.exceptions.attribute_error)
|
||||
|| e.fast_isinstance(vm.ctx.exceptions.value_error) =>
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
@@ -479,7 +479,7 @@ mod sys {
|
||||
}
|
||||
assert!(unraisable
|
||||
.exc_type
|
||||
.fast_issubclass(&vm.ctx.exceptions.exception_type));
|
||||
.fast_issubclass(vm.ctx.exceptions.exception_type));
|
||||
|
||||
// TODO: print module name and qualname
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ pub(crate) mod _thread {
|
||||
fn run_thread(func: ArgCallable, args: FuncArgs, vm: &VirtualMachine) {
|
||||
match func.invoke(args, vm) {
|
||||
Ok(_obj) => {}
|
||||
Err(e) if e.fast_isinstance(&vm.ctx.exceptions.system_exit) => {}
|
||||
Err(e) if e.fast_isinstance(vm.ctx.exceptions.system_exit) => {}
|
||||
Err(exc) => {
|
||||
vm.run_unraisable(
|
||||
exc,
|
||||
|
||||
@@ -24,7 +24,7 @@ mod _warnings {
|
||||
// TODO: Implement correctly
|
||||
let level = args.stacklevel.unwrap_or(1);
|
||||
let category = if let OptionalArg::Present(category) = args.category {
|
||||
if !category.fast_issubclass(&vm.ctx.exceptions.warning) {
|
||||
if !category.fast_issubclass(vm.ctx.exceptions.warning) {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"category must be a Warning subclass, not '{}'",
|
||||
category.class().name()
|
||||
|
||||
@@ -45,12 +45,12 @@ fn calculate_suggestions<'a>(
|
||||
}
|
||||
|
||||
pub fn offer_suggestions(exc: &PyBaseExceptionRef, vm: &VirtualMachine) -> Option<PyStrRef> {
|
||||
if exc.class().is(&vm.ctx.exceptions.attribute_error) {
|
||||
if exc.class().is(vm.ctx.exceptions.attribute_error) {
|
||||
let name = exc.as_object().to_owned().get_attr("name", vm).unwrap();
|
||||
let obj = exc.as_object().to_owned().get_attr("obj", vm).unwrap();
|
||||
|
||||
calculate_suggestions(vm.dir(Some(obj)).ok()?.borrow_vec().iter(), &name)
|
||||
} else if exc.class().is(&vm.ctx.exceptions.name_error) {
|
||||
} else if exc.class().is(vm.ctx.exceptions.name_error) {
|
||||
let name = exc.as_object().to_owned().get_attr("name", vm).unwrap();
|
||||
let mut tb = exc.traceback().unwrap();
|
||||
while let Some(traceback) = tb.next.clone() {
|
||||
|
||||
+144
-148
@@ -15,78 +15,78 @@ use crate::{
|
||||
#[derive(Debug, Clone)]
|
||||
#[non_exhaustive]
|
||||
pub struct TypeZoo {
|
||||
pub async_generator: PyTypeRef,
|
||||
pub async_generator_asend: PyTypeRef,
|
||||
pub async_generator_athrow: PyTypeRef,
|
||||
pub async_generator_wrapped_value: PyTypeRef,
|
||||
pub bytes_type: PyTypeRef,
|
||||
pub bytes_iterator_type: PyTypeRef,
|
||||
pub bytearray_type: PyTypeRef,
|
||||
pub bytearray_iterator_type: PyTypeRef,
|
||||
pub bool_type: PyTypeRef,
|
||||
pub callable_iterator: PyTypeRef,
|
||||
pub cell_type: PyTypeRef,
|
||||
pub classmethod_type: PyTypeRef,
|
||||
pub code_type: PyTypeRef,
|
||||
pub coroutine_type: PyTypeRef,
|
||||
pub coroutine_wrapper_type: PyTypeRef,
|
||||
pub dict_type: PyTypeRef,
|
||||
pub enumerate_type: PyTypeRef,
|
||||
pub filter_type: PyTypeRef,
|
||||
pub float_type: PyTypeRef,
|
||||
pub frame_type: PyTypeRef,
|
||||
pub frozenset_type: PyTypeRef,
|
||||
pub generator_type: PyTypeRef,
|
||||
pub int_type: PyTypeRef,
|
||||
pub iter_type: PyTypeRef,
|
||||
pub reverse_iter_type: PyTypeRef,
|
||||
pub complex_type: PyTypeRef,
|
||||
pub list_type: PyTypeRef,
|
||||
pub list_iterator_type: PyTypeRef,
|
||||
pub list_reverseiterator_type: PyTypeRef,
|
||||
pub str_iterator_type: PyTypeRef,
|
||||
pub dict_keyiterator_type: PyTypeRef,
|
||||
pub dict_reversekeyiterator_type: PyTypeRef,
|
||||
pub dict_valueiterator_type: PyTypeRef,
|
||||
pub dict_reversevalueiterator_type: PyTypeRef,
|
||||
pub dict_itemiterator_type: PyTypeRef,
|
||||
pub dict_reverseitemiterator_type: PyTypeRef,
|
||||
pub dict_keys_type: PyTypeRef,
|
||||
pub dict_values_type: PyTypeRef,
|
||||
pub dict_items_type: PyTypeRef,
|
||||
pub map_type: PyTypeRef,
|
||||
pub memoryview_type: PyTypeRef,
|
||||
pub tuple_type: PyTypeRef,
|
||||
pub tuple_iterator_type: PyTypeRef,
|
||||
pub set_type: PyTypeRef,
|
||||
pub set_iterator_type: PyTypeRef,
|
||||
pub staticmethod_type: PyTypeRef,
|
||||
pub super_type: PyTypeRef,
|
||||
pub str_type: PyTypeRef,
|
||||
pub range_type: PyTypeRef,
|
||||
pub range_iterator_type: PyTypeRef,
|
||||
pub longrange_iterator_type: PyTypeRef,
|
||||
pub slice_type: PyTypeRef,
|
||||
pub type_type: PyTypeRef,
|
||||
pub zip_type: PyTypeRef,
|
||||
pub function_type: PyTypeRef,
|
||||
pub builtin_function_or_method_type: PyTypeRef,
|
||||
pub method_descriptor_type: PyTypeRef,
|
||||
pub property_type: PyTypeRef,
|
||||
pub getset_type: PyTypeRef,
|
||||
pub module_type: PyTypeRef,
|
||||
pub namespace_type: PyTypeRef,
|
||||
pub bound_method_type: PyTypeRef,
|
||||
pub weakref_type: PyTypeRef,
|
||||
pub weakproxy_type: PyTypeRef,
|
||||
pub mappingproxy_type: PyTypeRef,
|
||||
pub traceback_type: PyTypeRef,
|
||||
pub object_type: PyTypeRef,
|
||||
pub ellipsis_type: PyTypeRef,
|
||||
pub none_type: PyTypeRef,
|
||||
pub not_implemented_type: PyTypeRef,
|
||||
pub generic_alias_type: PyTypeRef,
|
||||
pub union_type: PyTypeRef,
|
||||
pub async_generator: &'static PyTypeRef,
|
||||
pub async_generator_asend: &'static PyTypeRef,
|
||||
pub async_generator_athrow: &'static PyTypeRef,
|
||||
pub async_generator_wrapped_value: &'static PyTypeRef,
|
||||
pub bytes_type: &'static PyTypeRef,
|
||||
pub bytes_iterator_type: &'static PyTypeRef,
|
||||
pub bytearray_type: &'static PyTypeRef,
|
||||
pub bytearray_iterator_type: &'static PyTypeRef,
|
||||
pub bool_type: &'static PyTypeRef,
|
||||
pub callable_iterator: &'static PyTypeRef,
|
||||
pub cell_type: &'static PyTypeRef,
|
||||
pub classmethod_type: &'static PyTypeRef,
|
||||
pub code_type: &'static PyTypeRef,
|
||||
pub coroutine_type: &'static PyTypeRef,
|
||||
pub coroutine_wrapper_type: &'static PyTypeRef,
|
||||
pub dict_type: &'static PyTypeRef,
|
||||
pub enumerate_type: &'static PyTypeRef,
|
||||
pub filter_type: &'static PyTypeRef,
|
||||
pub float_type: &'static PyTypeRef,
|
||||
pub frame_type: &'static PyTypeRef,
|
||||
pub frozenset_type: &'static PyTypeRef,
|
||||
pub generator_type: &'static PyTypeRef,
|
||||
pub int_type: &'static PyTypeRef,
|
||||
pub iter_type: &'static PyTypeRef,
|
||||
pub reverse_iter_type: &'static PyTypeRef,
|
||||
pub complex_type: &'static PyTypeRef,
|
||||
pub list_type: &'static PyTypeRef,
|
||||
pub list_iterator_type: &'static PyTypeRef,
|
||||
pub list_reverseiterator_type: &'static PyTypeRef,
|
||||
pub str_iterator_type: &'static PyTypeRef,
|
||||
pub dict_keyiterator_type: &'static PyTypeRef,
|
||||
pub dict_reversekeyiterator_type: &'static PyTypeRef,
|
||||
pub dict_valueiterator_type: &'static PyTypeRef,
|
||||
pub dict_reversevalueiterator_type: &'static PyTypeRef,
|
||||
pub dict_itemiterator_type: &'static PyTypeRef,
|
||||
pub dict_reverseitemiterator_type: &'static PyTypeRef,
|
||||
pub dict_keys_type: &'static PyTypeRef,
|
||||
pub dict_values_type: &'static PyTypeRef,
|
||||
pub dict_items_type: &'static PyTypeRef,
|
||||
pub map_type: &'static PyTypeRef,
|
||||
pub memoryview_type: &'static PyTypeRef,
|
||||
pub tuple_type: &'static PyTypeRef,
|
||||
pub tuple_iterator_type: &'static PyTypeRef,
|
||||
pub set_type: &'static PyTypeRef,
|
||||
pub set_iterator_type: &'static PyTypeRef,
|
||||
pub staticmethod_type: &'static PyTypeRef,
|
||||
pub super_type: &'static PyTypeRef,
|
||||
pub str_type: &'static PyTypeRef,
|
||||
pub range_type: &'static PyTypeRef,
|
||||
pub range_iterator_type: &'static PyTypeRef,
|
||||
pub longrange_iterator_type: &'static PyTypeRef,
|
||||
pub slice_type: &'static PyTypeRef,
|
||||
pub type_type: &'static PyTypeRef,
|
||||
pub zip_type: &'static PyTypeRef,
|
||||
pub function_type: &'static PyTypeRef,
|
||||
pub builtin_function_or_method_type: &'static PyTypeRef,
|
||||
pub method_descriptor_type: &'static PyTypeRef,
|
||||
pub property_type: &'static PyTypeRef,
|
||||
pub getset_type: &'static PyTypeRef,
|
||||
pub module_type: &'static PyTypeRef,
|
||||
pub namespace_type: &'static PyTypeRef,
|
||||
pub bound_method_type: &'static PyTypeRef,
|
||||
pub weakref_type: &'static PyTypeRef,
|
||||
pub weakproxy_type: &'static PyTypeRef,
|
||||
pub mappingproxy_type: &'static PyTypeRef,
|
||||
pub traceback_type: &'static PyTypeRef,
|
||||
pub object_type: &'static PyTypeRef,
|
||||
pub ellipsis_type: &'static PyTypeRef,
|
||||
pub none_type: &'static PyTypeRef,
|
||||
pub not_implemented_type: &'static PyTypeRef,
|
||||
pub generic_alias_type: &'static PyTypeRef,
|
||||
pub union_type: &'static PyTypeRef,
|
||||
}
|
||||
|
||||
impl TypeZoo {
|
||||
@@ -95,86 +95,82 @@ impl TypeZoo {
|
||||
let (type_type, object_type, weakref_type) = crate::object::init_type_hierarchy();
|
||||
Self {
|
||||
// the order matters for type, object, weakref, and int
|
||||
type_type: type_::PyType::init_manually(type_type).clone(),
|
||||
object_type: object::PyBaseObject::init_manually(object_type).clone(),
|
||||
weakref_type: weakref::PyWeak::init_manually(weakref_type).clone(),
|
||||
int_type: int::PyInt::init_bare_type().clone(),
|
||||
type_type: type_::PyType::init_manually(type_type),
|
||||
object_type: object::PyBaseObject::init_manually(object_type),
|
||||
weakref_type: weakref::PyWeak::init_manually(weakref_type),
|
||||
int_type: int::PyInt::init_bare_type(),
|
||||
|
||||
// types exposed as builtins
|
||||
bool_type: bool_::PyBool::init_bare_type().clone(),
|
||||
bytearray_type: bytearray::PyByteArray::init_bare_type().clone(),
|
||||
bytes_type: bytes::PyBytes::init_bare_type().clone(),
|
||||
classmethod_type: classmethod::PyClassMethod::init_bare_type().clone(),
|
||||
complex_type: complex::PyComplex::init_bare_type().clone(),
|
||||
dict_type: dict::PyDict::init_bare_type().clone(),
|
||||
enumerate_type: enumerate::PyEnumerate::init_bare_type().clone(),
|
||||
float_type: float::PyFloat::init_bare_type().clone(),
|
||||
frozenset_type: set::PyFrozenSet::init_bare_type().clone(),
|
||||
filter_type: filter::PyFilter::init_bare_type().clone(),
|
||||
list_type: list::PyList::init_bare_type().clone(),
|
||||
map_type: map::PyMap::init_bare_type().clone(),
|
||||
memoryview_type: memory::PyMemoryView::init_bare_type().clone(),
|
||||
property_type: property::PyProperty::init_bare_type().clone(),
|
||||
range_type: range::PyRange::init_bare_type().clone(),
|
||||
set_type: set::PySet::init_bare_type().clone(),
|
||||
slice_type: slice::PySlice::init_bare_type().clone(),
|
||||
staticmethod_type: staticmethod::PyStaticMethod::init_bare_type().clone(),
|
||||
str_type: pystr::PyStr::init_bare_type().clone(),
|
||||
super_type: super_::PySuper::init_bare_type().clone(),
|
||||
tuple_type: tuple::PyTuple::init_bare_type().clone(),
|
||||
zip_type: zip::PyZip::init_bare_type().clone(),
|
||||
bool_type: bool_::PyBool::init_bare_type(),
|
||||
bytearray_type: bytearray::PyByteArray::init_bare_type(),
|
||||
bytes_type: bytes::PyBytes::init_bare_type(),
|
||||
classmethod_type: classmethod::PyClassMethod::init_bare_type(),
|
||||
complex_type: complex::PyComplex::init_bare_type(),
|
||||
dict_type: dict::PyDict::init_bare_type(),
|
||||
enumerate_type: enumerate::PyEnumerate::init_bare_type(),
|
||||
float_type: float::PyFloat::init_bare_type(),
|
||||
frozenset_type: set::PyFrozenSet::init_bare_type(),
|
||||
filter_type: filter::PyFilter::init_bare_type(),
|
||||
list_type: list::PyList::init_bare_type(),
|
||||
map_type: map::PyMap::init_bare_type(),
|
||||
memoryview_type: memory::PyMemoryView::init_bare_type(),
|
||||
property_type: property::PyProperty::init_bare_type(),
|
||||
range_type: range::PyRange::init_bare_type(),
|
||||
set_type: set::PySet::init_bare_type(),
|
||||
slice_type: slice::PySlice::init_bare_type(),
|
||||
staticmethod_type: staticmethod::PyStaticMethod::init_bare_type(),
|
||||
str_type: pystr::PyStr::init_bare_type(),
|
||||
super_type: super_::PySuper::init_bare_type(),
|
||||
tuple_type: tuple::PyTuple::init_bare_type(),
|
||||
zip_type: zip::PyZip::init_bare_type(),
|
||||
|
||||
// hidden internal types. is this really need to be cached here?
|
||||
async_generator: asyncgenerator::PyAsyncGen::init_bare_type().clone(),
|
||||
async_generator_asend: asyncgenerator::PyAsyncGenASend::init_bare_type().clone(),
|
||||
async_generator_athrow: asyncgenerator::PyAsyncGenAThrow::init_bare_type().clone(),
|
||||
async_generator_wrapped_value: asyncgenerator::PyAsyncGenWrappedValue::init_bare_type()
|
||||
.clone(),
|
||||
bound_method_type: function::PyBoundMethod::init_bare_type().clone(),
|
||||
builtin_function_or_method_type: builtinfunc::PyBuiltinFunction::init_bare_type()
|
||||
.clone(),
|
||||
bytearray_iterator_type: bytearray::PyByteArrayIterator::init_bare_type().clone(),
|
||||
bytes_iterator_type: bytes::PyBytesIterator::init_bare_type().clone(),
|
||||
callable_iterator: iter::PyCallableIterator::init_bare_type().clone(),
|
||||
cell_type: function::PyCell::init_bare_type().clone(),
|
||||
code_type: code::PyCode::init_bare_type().clone(),
|
||||
coroutine_type: coroutine::PyCoroutine::init_bare_type().clone(),
|
||||
coroutine_wrapper_type: coroutine::PyCoroutineWrapper::init_bare_type().clone(),
|
||||
dict_keys_type: dict::PyDictKeys::init_bare_type().clone(),
|
||||
dict_values_type: dict::PyDictValues::init_bare_type().clone(),
|
||||
dict_items_type: dict::PyDictItems::init_bare_type().clone(),
|
||||
dict_keyiterator_type: dict::PyDictKeyIterator::init_bare_type().clone(),
|
||||
dict_reversekeyiterator_type: dict::PyDictReverseKeyIterator::init_bare_type().clone(),
|
||||
dict_valueiterator_type: dict::PyDictValueIterator::init_bare_type().clone(),
|
||||
dict_reversevalueiterator_type: dict::PyDictReverseValueIterator::init_bare_type()
|
||||
.clone(),
|
||||
dict_itemiterator_type: dict::PyDictItemIterator::init_bare_type().clone(),
|
||||
dict_reverseitemiterator_type: dict::PyDictReverseItemIterator::init_bare_type()
|
||||
.clone(),
|
||||
ellipsis_type: slice::PyEllipsis::init_bare_type().clone(),
|
||||
frame_type: crate::frame::Frame::init_bare_type().clone(),
|
||||
function_type: function::PyFunction::init_bare_type().clone(),
|
||||
generator_type: generator::PyGenerator::init_bare_type().clone(),
|
||||
getset_type: getset::PyGetSet::init_bare_type().clone(),
|
||||
iter_type: iter::PySequenceIterator::init_bare_type().clone(),
|
||||
reverse_iter_type: enumerate::PyReverseSequenceIterator::init_bare_type().clone(),
|
||||
list_iterator_type: list::PyListIterator::init_bare_type().clone(),
|
||||
list_reverseiterator_type: list::PyListReverseIterator::init_bare_type().clone(),
|
||||
mappingproxy_type: mappingproxy::PyMappingProxy::init_bare_type().clone(),
|
||||
module_type: module::PyModule::init_bare_type().clone(),
|
||||
namespace_type: namespace::PyNamespace::init_bare_type().clone(),
|
||||
range_iterator_type: range::PyRangeIterator::init_bare_type().clone(),
|
||||
longrange_iterator_type: range::PyLongRangeIterator::init_bare_type().clone(),
|
||||
set_iterator_type: set::PySetIterator::init_bare_type().clone(),
|
||||
str_iterator_type: pystr::PyStrIterator::init_bare_type().clone(),
|
||||
traceback_type: traceback::PyTraceback::init_bare_type().clone(),
|
||||
tuple_iterator_type: tuple::PyTupleIterator::init_bare_type().clone(),
|
||||
weakproxy_type: weakproxy::PyWeakProxy::init_bare_type().clone(),
|
||||
method_descriptor_type: builtinfunc::PyBuiltinMethod::init_bare_type().clone(),
|
||||
none_type: singletons::PyNone::init_bare_type().clone(),
|
||||
not_implemented_type: singletons::PyNotImplemented::init_bare_type().clone(),
|
||||
generic_alias_type: genericalias::PyGenericAlias::init_bare_type().clone(),
|
||||
union_type: union_::PyUnion::init_bare_type().clone(),
|
||||
async_generator: asyncgenerator::PyAsyncGen::init_bare_type(),
|
||||
async_generator_asend: asyncgenerator::PyAsyncGenASend::init_bare_type(),
|
||||
async_generator_athrow: asyncgenerator::PyAsyncGenAThrow::init_bare_type(),
|
||||
async_generator_wrapped_value: asyncgenerator::PyAsyncGenWrappedValue::init_bare_type(),
|
||||
bound_method_type: function::PyBoundMethod::init_bare_type(),
|
||||
builtin_function_or_method_type: builtinfunc::PyBuiltinFunction::init_bare_type(),
|
||||
bytearray_iterator_type: bytearray::PyByteArrayIterator::init_bare_type(),
|
||||
bytes_iterator_type: bytes::PyBytesIterator::init_bare_type(),
|
||||
callable_iterator: iter::PyCallableIterator::init_bare_type(),
|
||||
cell_type: function::PyCell::init_bare_type(),
|
||||
code_type: code::PyCode::init_bare_type(),
|
||||
coroutine_type: coroutine::PyCoroutine::init_bare_type(),
|
||||
coroutine_wrapper_type: coroutine::PyCoroutineWrapper::init_bare_type(),
|
||||
dict_keys_type: dict::PyDictKeys::init_bare_type(),
|
||||
dict_values_type: dict::PyDictValues::init_bare_type(),
|
||||
dict_items_type: dict::PyDictItems::init_bare_type(),
|
||||
dict_keyiterator_type: dict::PyDictKeyIterator::init_bare_type(),
|
||||
dict_reversekeyiterator_type: dict::PyDictReverseKeyIterator::init_bare_type(),
|
||||
dict_valueiterator_type: dict::PyDictValueIterator::init_bare_type(),
|
||||
dict_reversevalueiterator_type: dict::PyDictReverseValueIterator::init_bare_type(),
|
||||
dict_itemiterator_type: dict::PyDictItemIterator::init_bare_type(),
|
||||
dict_reverseitemiterator_type: dict::PyDictReverseItemIterator::init_bare_type(),
|
||||
ellipsis_type: slice::PyEllipsis::init_bare_type(),
|
||||
frame_type: crate::frame::Frame::init_bare_type(),
|
||||
function_type: function::PyFunction::init_bare_type(),
|
||||
generator_type: generator::PyGenerator::init_bare_type(),
|
||||
getset_type: getset::PyGetSet::init_bare_type(),
|
||||
iter_type: iter::PySequenceIterator::init_bare_type(),
|
||||
reverse_iter_type: enumerate::PyReverseSequenceIterator::init_bare_type(),
|
||||
list_iterator_type: list::PyListIterator::init_bare_type(),
|
||||
list_reverseiterator_type: list::PyListReverseIterator::init_bare_type(),
|
||||
mappingproxy_type: mappingproxy::PyMappingProxy::init_bare_type(),
|
||||
module_type: module::PyModule::init_bare_type(),
|
||||
namespace_type: namespace::PyNamespace::init_bare_type(),
|
||||
range_iterator_type: range::PyRangeIterator::init_bare_type(),
|
||||
longrange_iterator_type: range::PyLongRangeIterator::init_bare_type(),
|
||||
set_iterator_type: set::PySetIterator::init_bare_type(),
|
||||
str_iterator_type: pystr::PyStrIterator::init_bare_type(),
|
||||
traceback_type: traceback::PyTraceback::init_bare_type(),
|
||||
tuple_iterator_type: tuple::PyTupleIterator::init_bare_type(),
|
||||
weakproxy_type: weakproxy::PyWeakProxy::init_bare_type(),
|
||||
method_descriptor_type: builtinfunc::PyBuiltinMethod::init_bare_type(),
|
||||
none_type: singletons::PyNone::init_bare_type(),
|
||||
not_implemented_type: singletons::PyNotImplemented::init_bare_type(),
|
||||
generic_alias_type: genericalias::PyGenericAlias::init_bare_type(),
|
||||
union_type: union_::PyUnion::init_bare_type(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -240,23 +240,23 @@ impl Context {
|
||||
.map(|v| PyRef::new_ref(PyInt::from(BigInt::from(v)), types.int_type.clone(), None))
|
||||
.collect();
|
||||
|
||||
let true_value = create_object(PyInt::from(1), &types.bool_type);
|
||||
let false_value = create_object(PyInt::from(0), &types.bool_type);
|
||||
let true_value = create_object(PyInt::from(1), types.bool_type);
|
||||
let false_value = create_object(PyInt::from(0), types.bool_type);
|
||||
|
||||
let empty_tuple = create_object(
|
||||
PyTuple::new_unchecked(Vec::new().into_boxed_slice()),
|
||||
&types.tuple_type,
|
||||
types.tuple_type,
|
||||
);
|
||||
let empty_frozenset =
|
||||
PyRef::new_ref(PyFrozenSet::default(), types.frozenset_type.clone(), None);
|
||||
|
||||
let string_pool = StringPool::default();
|
||||
let names = unsafe { ConstName::new(&string_pool, &types.str_type) };
|
||||
let names = unsafe { ConstName::new(&string_pool, types.str_type) };
|
||||
|
||||
let slot_new_wrapper = create_object(
|
||||
PyNativeFuncDef::new(PyType::__new__.into_func(), names.__new__.to_owned())
|
||||
.into_function(),
|
||||
&types.builtin_function_or_method_type,
|
||||
types.builtin_function_or_method_type,
|
||||
)
|
||||
.into();
|
||||
|
||||
|
||||
+7
-7
@@ -468,9 +468,9 @@ impl VirtualMachine {
|
||||
// Extract elements from item, if possible:
|
||||
let cls = value.class();
|
||||
let list_borrow;
|
||||
let slice = if cls.is(&self.ctx.types.tuple_type) {
|
||||
let slice = if cls.is(self.ctx.types.tuple_type) {
|
||||
value.payload::<PyTuple>().unwrap().as_slice()
|
||||
} else if cls.is(&self.ctx.types.list_type) {
|
||||
} else if cls.is(self.ctx.types.list_type) {
|
||||
list_borrow = value.payload::<PyList>().unwrap().borrow_vec();
|
||||
&list_borrow
|
||||
} else {
|
||||
@@ -519,7 +519,7 @@ impl VirtualMachine {
|
||||
{
|
||||
let iter = value.to_owned().get_iter(self)?;
|
||||
let cap = match self.length_hint_opt(value.to_owned()) {
|
||||
Err(e) if e.class().is(&self.ctx.exceptions.runtime_error) => return Err(e),
|
||||
Err(e) if e.class().is(self.ctx.exceptions.runtime_error) => return Err(e),
|
||||
Ok(Some(value)) => Some(value),
|
||||
// Use a power of 2 as a default capacity.
|
||||
_ => None,
|
||||
@@ -549,7 +549,7 @@ impl VirtualMachine {
|
||||
{
|
||||
match obj.get_attr(attr_name, self) {
|
||||
Ok(attr) => Ok(Some(attr)),
|
||||
Err(e) if e.fast_isinstance(&self.ctx.exceptions.attribute_error) => Ok(None),
|
||||
Err(e) if e.fast_isinstance(self.ctx.exceptions.attribute_error) => Ok(None),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
@@ -560,7 +560,7 @@ impl VirtualMachine {
|
||||
obj: PyObjectRef,
|
||||
name: PyStrRef,
|
||||
) {
|
||||
if exc.class().is(&self.ctx.exceptions.attribute_error) {
|
||||
if exc.class().is(self.ctx.exceptions.attribute_error) {
|
||||
let exc = exc.as_object();
|
||||
exc.set_attr("name", name, self).unwrap();
|
||||
exc.set_attr("obj", obj, self).unwrap();
|
||||
@@ -676,7 +676,7 @@ impl VirtualMachine {
|
||||
}
|
||||
|
||||
pub fn handle_exit_exception(&self, exc: PyBaseExceptionRef) -> i32 {
|
||||
if exc.fast_isinstance(&self.ctx.exceptions.system_exit) {
|
||||
if exc.fast_isinstance(self.ctx.exceptions.system_exit) {
|
||||
let args = exc.args();
|
||||
let msg = match args.as_slice() {
|
||||
[] => return 0,
|
||||
@@ -791,7 +791,7 @@ fn get_importer(path: &str, vm: &VirtualMachine) -> PyResult<Option<PyObjectRef>
|
||||
importer = Some(imp);
|
||||
break;
|
||||
}
|
||||
Err(e) if e.fast_isinstance(&vm.ctx.exceptions.import_error) => continue,
|
||||
Err(e) if e.fast_isinstance(vm.ctx.exceptions.import_error) => continue,
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ where
|
||||
let vm_owns_obj = |intp: NonNull<VirtualMachine>| {
|
||||
// SAFETY: all references in VM_STACK should be valid
|
||||
let vm = unsafe { intp.as_ref() };
|
||||
obj.fast_isinstance(&vm.ctx.types.object_type)
|
||||
obj.fast_isinstance(vm.ctx.types.object_type)
|
||||
};
|
||||
VM_STACK.with(|vms| {
|
||||
let intp = match vms.borrow().iter().copied().exactly_one() {
|
||||
|
||||
+2
-2
@@ -284,7 +284,7 @@ impl VirtualMachine {
|
||||
) -> PyBaseExceptionRef {
|
||||
self.new_downcast_error(
|
||||
"payload",
|
||||
&self.ctx.exceptions.runtime_error,
|
||||
self.ctx.exceptions.runtime_error,
|
||||
class,
|
||||
obj.as_object(),
|
||||
)
|
||||
@@ -297,7 +297,7 @@ impl VirtualMachine {
|
||||
) -> PyBaseExceptionRef {
|
||||
self.new_downcast_error(
|
||||
"type",
|
||||
&self.ctx.exceptions.type_error,
|
||||
self.ctx.exceptions.type_error,
|
||||
class,
|
||||
obj.as_object(),
|
||||
)
|
||||
|
||||
+2
-2
@@ -74,7 +74,7 @@ impl VirtualMachine {
|
||||
match iter.length(self) {
|
||||
Ok(len) => return Ok(Some(len)),
|
||||
Err(e) => {
|
||||
if !e.fast_isinstance(&self.ctx.exceptions.type_error) {
|
||||
if !e.fast_isinstance(self.ctx.exceptions.type_error) {
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,7 @@ impl VirtualMachine {
|
||||
res
|
||||
}
|
||||
Err(e) => {
|
||||
return if e.fast_isinstance(&self.ctx.exceptions.type_error) {
|
||||
return if e.fast_isinstance(self.ctx.exceptions.type_error) {
|
||||
Ok(None)
|
||||
} else {
|
||||
Err(e)
|
||||
|
||||
@@ -62,10 +62,10 @@ pub fn js_err_to_py_err(vm: &VirtualMachine, js_err: &JsValue) -> PyBaseExceptio
|
||||
match js_err.dyn_ref::<js_sys::Error>() {
|
||||
Some(err) => {
|
||||
let exc_type = match String::from(err.name()).as_str() {
|
||||
"TypeError" => &vm.ctx.exceptions.type_error,
|
||||
"ReferenceError" => &vm.ctx.exceptions.name_error,
|
||||
"SyntaxError" => &vm.ctx.exceptions.syntax_error,
|
||||
_ => &vm.ctx.exceptions.exception_type,
|
||||
"TypeError" => vm.ctx.exceptions.type_error,
|
||||
"ReferenceError" => vm.ctx.exceptions.name_error,
|
||||
"SyntaxError" => vm.ctx.exceptions.syntax_error,
|
||||
_ => vm.ctx.exceptions.exception_type,
|
||||
}
|
||||
.clone();
|
||||
vm.new_exception_msg(exc_type, err.message().into())
|
||||
@@ -79,7 +79,7 @@ pub fn js_err_to_py_err(vm: &VirtualMachine, js_err: &JsValue) -> PyBaseExceptio
|
||||
|
||||
pub fn py_to_js(vm: &VirtualMachine, py_obj: PyObjectRef) -> JsValue {
|
||||
if let Some(ref wasm_id) = vm.wasm_id {
|
||||
if py_obj.fast_isinstance(&vm.ctx.types.function_type) {
|
||||
if py_obj.fast_isinstance(vm.ctx.types.function_type) {
|
||||
let wasm_vm = WASMVirtualMachine {
|
||||
id: wasm_id.clone(),
|
||||
};
|
||||
|
||||
@@ -623,7 +623,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
let module = _js::make_module(vm);
|
||||
|
||||
let ctx = &vm.ctx;
|
||||
let js_error = PyType::new_simple_ref("JSError", &vm.ctx.exceptions.exception_type).unwrap();
|
||||
let js_error = PyType::new_simple_ref("JSError", vm.ctx.exceptions.exception_type).unwrap();
|
||||
extend_class!(ctx, &js_error, {
|
||||
"value" => ctx.new_readonly_getset("value", js_error.clone(), |exc: PyBaseExceptionRef| exc.get_arg(0)),
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ pub fn make_stdout_object(
|
||||
let ctx = &vm.ctx;
|
||||
// there's not really any point to storing this class so that there's a consistent type object,
|
||||
// we just want a half-decent repr() output
|
||||
let cls = py_class!(ctx, "JSStdout", &vm.ctx.types.object_type, {});
|
||||
let cls = py_class!(ctx, "JSStdout", vm.ctx.types.object_type, {});
|
||||
let write_method = ctx.new_method(
|
||||
"write",
|
||||
cls.clone(),
|
||||
|
||||
Reference in new issue
Block a user