Skip to content

derive(PyValue) not to depend on local context #3127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion derive/src/pyvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ pub(crate) fn impl_pyvalue(input: DeriveInput) -> std::result::Result<TokenStrea

let ret = quote! {
impl ::rustpython_vm::PyValue for #ty {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
fn class(_vm: &::rustpython_vm::VirtualMachine) -> &rustpython_vm::builtins::PyTypeRef {
use ::rustpython_vm::StaticType;
Self::static_type()
}
}
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod array {
sliceable::{saturate_index, PySliceableSequence, PySliceableSequenceMut, SequenceIndex},
slots::{AsBuffer, Comparable, Iterable, PyComparisonOp, PyIter, SlotConstructor},
IdProtocol, IntoPyObject, IntoPyResult, PyComparisonValue, PyObjectRef, PyRef, PyResult,
PyValue, StaticType, TryFromObject, TypeProtocol, VirtualMachine,
PyValue, TryFromObject, TypeProtocol, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use itertools::Itertools;
Expand Down
3 changes: 1 addition & 2 deletions vm/src/stdlib/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ mod _collections {
Comparable, Hashable, Iterable, PyComparisonOp, PyIter, SlotConstructor, Unhashable,
},
vm::ReprGuard,
PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TypeProtocol,
VirtualMachine,
PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use itertools::Itertools;
Expand Down
4 changes: 2 additions & 2 deletions vm/src/stdlib/csv.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::common::lock::PyMutex;
use crate::{
builtins::{PyStr, PyStrRef, PyTypeRef},
builtins::{PyStr, PyStrRef},
function::{ArgIterable, ArgumentError, FromArgs, FuncArgs},
iterator,
slots::PyIter,
types::create_simple_type,
PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject, TypeProtocol,
PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol,
VirtualMachine,
};
use itertools::{self, Itertools};
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/hashlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod hashlib {
use crate::{
builtins::{PyBytes, PyBytesRef, PyStrRef, PyTypeRef},
function::{FuncArgs, OptionalArg},
PyResult, PyValue, StaticType, VirtualMachine,
PyResult, PyValue, VirtualMachine,
};
use blake2::{Blake2b, Blake2s};
use digest::DynDigest;
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3682,7 +3682,7 @@ mod fileio {
use crate::function::{FuncArgs, OptionalArg};
use crate::stdlib::os;
use crate::vm::VirtualMachine;
use crate::{PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject, TypeProtocol};
use crate::{PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol};
use crossbeam_utils::atomic::AtomicCell;
use std::io::{Read, Write};

Expand Down
4 changes: 2 additions & 2 deletions vm/src/stdlib/itertools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ mod decl {
function::{ArgCallable, FuncArgs, OptionalArg, OptionalOption, PosArgs},
iterator::{call_next, get_iter, get_next_object},
slots::{PyIter, SlotConstructor},
IdProtocol, IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, PyWeakRef, StaticType,
TypeProtocol, VirtualMachine,
IdProtocol, IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, PyWeakRef, TypeProtocol,
VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use num_bigint::BigInt;
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod _json {
function::{FuncArgs, OptionalArg},
iterator,
slots::{Callable, SlotConstructor},
IdProtocol, IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject,
IdProtocol, IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
VirtualMachine,
};
use num_bigint::BigInt;
Expand Down
4 changes: 2 additions & 2 deletions vm/src/stdlib/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ mod _operator {
},
utils::Either,
vm::ReprGuard,
IdProtocol, ItemProtocol, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryIntoRef,
TypeProtocol, VirtualMachine,
IdProtocol, ItemProtocol, PyObjectRef, PyRef, PyResult, PyValue, TryIntoRef, TypeProtocol,
VirtualMachine,
};

/// Same as a < b.
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ pub(super) mod _os {
suppress_iph,
utils::Either,
vm::{ReprGuard, VirtualMachine},
IntoPyObject, PyObjectRef, PyRef, PyResult, PyStructSequence, PyValue, StaticType,
IntoPyObject, PyObjectRef, PyRef, PyResult, PyStructSequence, PyValue,
TryFromBorrowedObject, TryFromObject, TypeProtocol,
};
use crossbeam_utils::atomic::AtomicCell;
Expand Down
3 changes: 1 addition & 2 deletions vm/src/stdlib/posix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ pub mod module {
_os, fs_metadata,
},
utils::{Either, ToCString},
IntoPyObject, ItemProtocol, PyObjectRef, PyResult, PyValue, StaticType, TryFromObject,
VirtualMachine,
IntoPyObject, ItemProtocol, PyObjectRef, PyResult, PyValue, TryFromObject, VirtualMachine,
};
use bitflags::bitflags;
use nix::fcntl;
Expand Down
1 change: 0 additions & 1 deletion vm/src/stdlib/pyexpat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ mod _pyexpat {
use crate::builtins::{PyStr, PyStrRef, PyTypeRef};
use crate::byteslike::ArgBytesLike;
use crate::function::{IntoFuncArgs, OptionalArg};
use crate::pyobject::StaticType;
use crate::{
ItemProtocol, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
VirtualMachine,
Expand Down
3 changes: 1 addition & 2 deletions vm/src/stdlib/pystruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ pub(crate) mod _struct {
function::PosArgs,
slots::{PyIter, SlotConstructor},
utils::Either,
IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject,
VirtualMachine,
IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use half::f16;
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod _random {
builtins::{PyIntRef, PyTypeRef},
function::OptionalOption,
slots::SlotConstructor,
PyObjectRef, PyResult, PyValue, StaticType, VirtualMachine,
PyObjectRef, PyResult, PyValue, VirtualMachine,
};
use num_bigint::{BigInt, Sign};
use num_traits::{Signed, Zero};
Expand Down
4 changes: 2 additions & 2 deletions vm/src/stdlib/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,11 @@ mod decl {
#[cfg(unix)]
pub(super) mod poll {
use super::*;
use crate::builtins::{PyFloat, PyTypeRef};
use crate::builtins::PyFloat;
use crate::common::lock::PyMutex;
use crate::function::OptionalArg;
use crate::stdlib::io::Fildes;
use crate::{IntoPyObject, PyValue, StaticType, TypeProtocol};
use crate::{IntoPyObject, PyValue, TypeProtocol};
use libc::pollfd;
use num_traits::ToPrimitive;
use std::time;
Expand Down
4 changes: 2 additions & 2 deletions vm/src/stdlib/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
exceptions::{IntoPyException, PyBaseExceptionRef},
function::{FuncArgs, OptionalArg, OptionalOption},
utils::{Either, ToCString},
IntoPyObject, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType,
TryFromBorrowedObject, TryFromObject, TypeProtocol, VirtualMachine,
IntoPyObject, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromBorrowedObject,
TryFromObject, TypeProtocol, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use gethostname::gethostname;
Expand Down
3 changes: 1 addition & 2 deletions vm/src/stdlib/sre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ mod _sre {
buffer::PyBuffer,
builtins::{
PyCallableIterator, PyDictRef, PyInt, PyList, PyListRef, PyStr, PyStrRef, PyTupleRef,
PyTypeRef,
},
common::hash::PyHash,
function::{ArgCallable, OptionalArg, PosArgs},
slots::{Comparable, Hashable},
IntoPyObject, ItemProtocol, PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue,
StaticType, TryFromBorrowedObject, TryFromObject, VirtualMachine,
TryFromBorrowedObject, TryFromObject, VirtualMachine,
};
use core::str;
use crossbeam_utils::atomic::AtomicCell;
Expand Down
3 changes: 1 addition & 2 deletions vm/src/stdlib/ssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use crate::{
slots::SlotConstructor,
stdlib::os::PyPathLike,
utils::{Either, ToCString},
IntoPyObject, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType,
VirtualMachine,
IntoPyObject, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use foreign_types_shared::{ForeignType, ForeignTypeRef};
Expand Down
4 changes: 2 additions & 2 deletions vm/src/stdlib/symtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ pub(crate) use decl::make_module;
#[pymodule(name = "symtable")]
mod decl {
use crate::{
builtins::{PyStrRef, PyTypeRef},
builtins::PyStrRef,
compile::{self, Symbol, SymbolScope, SymbolTable, SymbolTableType},
PyRef, PyResult, PyValue, StaticType, VirtualMachine,
PyRef, PyResult, PyValue, VirtualMachine,
};
use std::fmt;

Expand Down
4 changes: 2 additions & 2 deletions vm/src/stdlib/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
py_io,
slots::{SlotGetattro, SlotSetattro},
utils::Either,
IdProtocol, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType,
TypeProtocol, VirtualMachine,
IdProtocol, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
VirtualMachine,
};
use parking_lot::{
lock_api::{RawMutex as RawMutexT, RawMutexTimed, RawReentrantMutex},
Expand Down
5 changes: 2 additions & 3 deletions vm/src/stdlib/unicodedata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
*/

use crate::{
builtins::{PyStrRef, PyTypeRef},
function::OptionalArg,
PyClassImpl, PyObject, PyObjectRef, PyResult, PyValue, StaticType, VirtualMachine,
builtins::PyStrRef, function::OptionalArg, PyClassImpl, PyObject, PyObjectRef, PyResult,
PyValue, VirtualMachine,
};
use itertools::Itertools;
use unic_char_property::EnumeratedCharProperty;
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/winreg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::common::lock::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard};
use crate::{
builtins::{PyStrRef, PyTypeRef},
exceptions::IntoPyException,
PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject, VirtualMachine,
PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine,
};
use std::convert::TryInto;
use std::ffi::OsStr;
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/zlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod decl {
exceptions::PyBaseExceptionRef,
function::OptionalArg,
types::create_simple_type,
IntoPyRef, PyResult, PyValue, StaticType, VirtualMachine,
IntoPyRef, PyResult, PyValue, VirtualMachine,
};
use adler32::RollingAdler32 as Adler32;
use crc32fast::Hasher as Crc32;
Expand Down
4 changes: 2 additions & 2 deletions wasm/lib/src/browser_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;

use rustpython_vm::builtins::{PyDictRef, PyStrRef, PyTypeRef};
use rustpython_vm::builtins::{PyDictRef, PyStrRef};
use rustpython_vm::function::{ArgCallable, OptionalArg};
use rustpython_vm::import::import_file;
use rustpython_vm::{
IntoPyObject, PyClassImpl, PyObject, PyObjectRef, PyResult, PyValue, StaticType, VirtualMachine,
IntoPyObject, PyClassImpl, PyObject, PyObjectRef, PyResult, PyValue, VirtualMachine,
};

use crate::{convert, js_module::PyPromise, vm_class::weak_vm, wasm_builtins::window};
Expand Down
2 changes: 1 addition & 1 deletion wasm/lib/src/js_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustpython_vm::types::create_simple_type;
use rustpython_vm::VirtualMachine;
use rustpython_vm::{
function::ArgCallable, IntoPyObject, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue,
StaticType, TryFromObject,
TryFromObject,
};

#[wasm_bindgen(inline_js = "
Expand Down