Merge pull request #3099 from deantvv/impl-pyvalue

impl `#[derive(PyValue)]` for static_type
This commit is contained in:
Jeong YunWon authored and GitHub committed 2021-09-22 01:16:19 +09:00
commit 3a0c2bb752
27 files changed
+99 -484

No files matched your search

+7
View File
@@ -17,6 +17,7 @@ mod from_args;
mod pyclass;
mod pymodule;
mod pystructseq;
mod pyvalue;
use error::{extract_spans, Diagnostic};
use proc_macro::TokenStream;
@@ -95,3 +96,9 @@ pub fn py_compile(input: TokenStream) -> TokenStream {
pub fn py_freeze(input: TokenStream) -> TokenStream {
result_to_tokens(compile_bytecode::impl_py_freeze(input.into()))
}
#[proc_macro_derive(PyValue)]
pub fn pyvalue(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
result_to_tokens(pyvalue::impl_pyvalue(input))
}
+17
View File
@@ -0,0 +1,17 @@
use super::Diagnostic;
use proc_macro2::TokenStream;
use quote::quote;
use syn::DeriveInput;
pub(crate) fn impl_pyvalue(input: DeriveInput) -> std::result::Result<TokenStream, Diagnostic> {
let ty = &input.ident;
let ret = quote! {
impl ::rustpython_vm::PyValue for #ty {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
};
Ok(ret)
}
+2 -14
View File
@@ -589,7 +589,7 @@ mod array {
#[pyattr]
#[pyclass(name = "array")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
pub struct PyArray {
array: PyRwLock<ArrayContentType>,
exports: AtomicCell<usize>,
@@ -597,12 +597,6 @@ mod array {
pub type PyArrayRef = PyRef<PyArray>;
impl PyValue for PyArray {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl From<ArrayContentType> for PyArray {
fn from(array: ArrayContentType) -> Self {
PyArray {
@@ -1198,18 +1192,12 @@ mod array {
#[pyattr]
#[pyclass(name = "array_iterator")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
pub struct PyArrayIter {
position: AtomicCell<usize>,
array: PyArrayRef,
}
impl PyValue for PyArrayIter {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl(with(PyIter))]
impl PyArrayIter {}
+1 -7
View File
@@ -44,7 +44,7 @@ fn get_node_field_opt(
}
#[pyclass(module = "_ast", name = "AST")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
pub(crate) struct AstNode;
#[pyimpl(flags(HAS_DICT))]
@@ -84,12 +84,6 @@ impl AstNode {
const MODULE_NAME: &str = "_ast";
pub const PY_COMPILE_FLAG_AST_ONLY: i32 = 0x0400;
impl PyValue for AstNode {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
trait Node: Sized {
fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef;
fn ast_from_object(vm: &VirtualMachine, object: PyObjectRef) -> PyResult<Self>;
+3 -21
View File
@@ -26,7 +26,7 @@ mod _collections {
#[pyattr]
#[pyclass(name = "deque")]
#[derive(Debug, Default)]
#[derive(Debug, Default, PyValue)]
struct PyDeque {
deque: PyRwLock<VecDeque<PyObjectRef>>,
maxlen: Option<usize>,
@@ -35,12 +35,6 @@ mod _collections {
type PyDequeRef = PyRef<PyDeque>;
impl PyValue for PyDeque {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct PyDequeOptions {
#[pyarg(any, optional)]
@@ -577,7 +571,7 @@ mod _collections {
#[pyattr]
#[pyclass(name = "_deque_iterator")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyDequeIterator {
position: AtomicCell<usize>,
status: AtomicCell<IterStatus>,
@@ -585,12 +579,6 @@ mod _collections {
deque: PyDequeRef,
}
impl PyValue for PyDequeIterator {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct DequeIterArgs {
#[pyarg(positional)]
@@ -680,7 +668,7 @@ mod _collections {
#[pyattr]
#[pyclass(name = "_deque_reverse_iterator")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyReverseDequeIterator {
position: AtomicCell<usize>,
status: AtomicCell<IterStatus>,
@@ -688,12 +676,6 @@ mod _collections {
deque: PyDequeRef,
}
impl PyValue for PyReverseDequeIterator {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl SlotConstructor for PyReverseDequeIterator {
type Args = (DequeIterArgs, KwArgs);
+2 -12
View File
@@ -86,6 +86,7 @@ struct ReadState {
}
#[pyclass(module = "_csv", name = "reader")]
#[derive(PyValue)]
struct Reader {
iter: PyObjectRef,
state: PyMutex<ReadState>,
@@ -97,12 +98,6 @@ impl fmt::Debug for Reader {
}
}
impl PyValue for Reader {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl(with(PyIter))]
impl Reader {}
impl PyIter for Reader {
@@ -193,6 +188,7 @@ struct WriteState {
}
#[pyclass(module = "_csv", name = "writer")]
#[derive(PyValue)]
struct Writer {
write: PyObjectRef,
state: PyMutex<WriteState>,
@@ -204,12 +200,6 @@ impl fmt::Debug for Writer {
}
}
impl PyValue for Writer {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl Writer {
#[pymethod]
+1 -6
View File
@@ -19,6 +19,7 @@ mod hashlib {
#[pyattr]
#[pyclass(module = "hashlib", name = "hasher")]
#[derive(PyValue)]
struct PyHasher {
name: String,
buffer: PyRwLock<HashWrapper>,
@@ -30,12 +31,6 @@ mod hashlib {
}
}
impl PyValue for PyHasher {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl PyHasher {
fn new(name: &str, d: HashWrapper) -> Self {
+8 -51
View File
@@ -1638,15 +1638,10 @@ mod _io {
#[pyattr]
#[pyclass(name = "BufferedReader", base = "_BufferedIOBase")]
#[derive(Debug, Default)]
#[derive(Debug, Default, PyValue)]
struct BufferedReader {
data: PyThreadMutex<BufferedData>,
}
impl PyValue for BufferedReader {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl BufferedMixin for BufferedReader {
const READABLE: bool = true;
const WRITABLE: bool = false;
@@ -1692,15 +1687,10 @@ mod _io {
#[pyattr]
#[pyclass(name = "BufferedWriter", base = "_BufferedIOBase")]
#[derive(Debug, Default)]
#[derive(Debug, Default, PyValue)]
struct BufferedWriter {
data: PyThreadMutex<BufferedData>,
}
impl PyValue for BufferedWriter {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl BufferedMixin for BufferedWriter {
const READABLE: bool = false;
const WRITABLE: bool = true;
@@ -1725,15 +1715,10 @@ mod _io {
#[pyattr]
#[pyclass(name = "BufferedRandom", base = "_BufferedIOBase")]
#[derive(Debug, Default)]
#[derive(Debug, Default, PyValue)]
struct BufferedRandom {
data: PyThreadMutex<BufferedData>,
}
impl PyValue for BufferedRandom {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl BufferedMixin for BufferedRandom {
const READABLE: bool = true;
const WRITABLE: bool = true;
@@ -1768,16 +1753,11 @@ mod _io {
#[pyattr]
#[pyclass(name = "BufferedRWPair", base = "_BufferedIOBase")]
#[derive(Debug, Default)]
#[derive(Debug, Default, PyValue)]
struct BufferedRWPair {
read: BufferedReader,
write: BufferedWriter,
}
impl PyValue for BufferedRWPair {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl BufferedReadable for BufferedRWPair {
type Reader = BufferedReader;
fn reader(&self) -> &Self::Reader {
@@ -2182,15 +2162,10 @@ mod _io {
#[pyattr]
#[pyclass(name = "TextIOWrapper", base = "_TextIOBase")]
#[derive(Debug, Default)]
#[derive(Debug, Default, PyValue)]
struct TextIOWrapper {
data: PyThreadMutex<Option<TextIOData>>,
}
impl PyValue for TextIOWrapper {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl(flags(BASETYPE))]
impl TextIOWrapper {
@@ -3043,7 +3018,7 @@ mod _io {
#[pyattr]
#[pyclass(name = "StringIO", base = "_TextIOBase")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct StringIO {
buffer: PyRwLock<BufferedIO>,
closed: AtomicCell<bool>,
@@ -3051,12 +3026,6 @@ mod _io {
type StringIORef = PyRef<StringIO>;
impl PyValue for StringIO {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct StringIONewArgs {
#[pyarg(positional, optional)]
@@ -3198,7 +3167,7 @@ mod _io {
#[pyattr]
#[pyclass(name = "BytesIO", base = "_BufferedIOBase")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct BytesIO {
buffer: PyRwLock<BufferedIO>,
closed: AtomicCell<bool>,
@@ -3207,12 +3176,6 @@ mod _io {
type BytesIORef = PyRef<BytesIO>;
impl PyValue for BytesIO {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl SlotConstructor for BytesIO {
type Args = OptionalArg<Option<PyBytesRef>>;
@@ -3823,7 +3786,7 @@ mod fileio {
#[pyattr]
#[pyclass(module = "io", name, base = "_RawIOBase")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
pub(super) struct FileIO {
fd: AtomicCell<i32>,
closefd: AtomicCell<bool>,
@@ -3831,12 +3794,6 @@ mod fileio {
seekable: AtomicCell<Option<bool>>,
}
impl PyValue for FileIO {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct FileIOArgs {
#[pyarg(positional)]
+20 -139
View File
@@ -24,19 +24,13 @@ mod decl {
#[pyattr]
#[pyclass(name = "chain")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsChain {
iterables: Vec<PyObjectRef>,
cur_idx: AtomicCell<usize>,
cached_iter: PyRwLock<Option<PyObjectRef>>,
}
impl PyValue for PyItertoolsChain {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl(with(PyIter))]
impl PyItertoolsChain {
#[pyslot]
@@ -102,18 +96,12 @@ mod decl {
#[pyattr]
#[pyclass(name = "compress")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsCompress {
data: PyObjectRef,
selector: PyObjectRef,
}
impl PyValue for PyItertoolsCompress {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct CompressNewArgs {
#[pyarg(positional)]
@@ -160,18 +148,12 @@ mod decl {
#[pyattr]
#[pyclass(name = "count")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsCount {
cur: PyRwLock<BigInt>,
step: BigInt,
}
impl PyValue for PyItertoolsCount {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct CountNewArgs {
#[pyarg(positional, optional)]
@@ -219,19 +201,13 @@ mod decl {
#[pyattr]
#[pyclass(name = "cycle")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsCycle {
iter: PyObjectRef,
saved: PyRwLock<Vec<PyObjectRef>>,
index: AtomicCell<usize>,
}
impl PyValue for PyItertoolsCycle {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl SlotConstructor for PyItertoolsCycle {
type Args = PyObjectRef;
@@ -275,18 +251,12 @@ mod decl {
#[pyattr]
#[pyclass(name = "repeat")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsRepeat {
object: PyObjectRef,
times: Option<PyRwLock<usize>>,
}
impl PyValue for PyItertoolsRepeat {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct PyRepeatNewArgs {
#[pyarg(any)]
@@ -371,18 +341,12 @@ mod decl {
#[pyattr]
#[pyclass(name = "starmap")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsStarmap {
function: PyObjectRef,
iter: PyObjectRef,
}
impl PyValue for PyItertoolsStarmap {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct StarmapNewArgs {
#[pyarg(positional)]
@@ -418,19 +382,13 @@ mod decl {
#[pyattr]
#[pyclass(name = "takewhile")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsTakewhile {
predicate: PyObjectRef,
iterable: PyObjectRef,
stop_flag: AtomicCell<bool>,
}
impl PyValue for PyItertoolsTakewhile {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct TakewhileNewArgs {
#[pyarg(positional)]
@@ -486,19 +444,13 @@ mod decl {
#[pyattr]
#[pyclass(name = "dropwhile")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsDropwhile {
predicate: PyCallable,
iterable: PyObjectRef,
start_flag: AtomicCell<bool>,
}
impl PyValue for PyItertoolsDropwhile {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct DropwhileNewArgs {
#[pyarg(positional)]
@@ -579,18 +531,13 @@ mod decl {
#[pyattr]
#[pyclass(name = "groupby")]
#[derive(PyValue)]
struct PyItertoolsGroupBy {
iterable: PyObjectRef,
key_func: Option<PyObjectRef>,
state: PyMutex<GroupByState>,
}
impl PyValue for PyItertoolsGroupBy {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl fmt::Debug for PyItertoolsGroupBy {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("PyItertoolsGroupBy")
@@ -680,19 +627,13 @@ mod decl {
#[pyattr]
#[pyclass(name = "_grouper")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsGrouper {
groupby: PyRef<PyItertoolsGroupBy>,
}
type PyItertoolsGrouperRef = PyRef<PyItertoolsGrouper>;
impl PyValue for PyItertoolsGrouper {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl(with(PyIter))]
impl PyItertoolsGrouper {}
impl PyIter for PyItertoolsGrouper {
@@ -727,7 +668,7 @@ mod decl {
#[pyattr]
#[pyclass(name = "islice")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsIslice {
iterable: PyObjectRef,
cur: AtomicCell<usize>,
@@ -736,12 +677,6 @@ mod decl {
step: usize,
}
impl PyValue for PyItertoolsIslice {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
// Restrict obj to ints with value 0 <= val <= sys.maxsize (isize::MAX).
// On failure (out of range, non-int object) a ValueError is raised.
fn pyobject_to_opt_usize(
@@ -856,18 +791,12 @@ mod decl {
#[pyattr]
#[pyclass(name = "filterfalse")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsFilterFalse {
predicate: PyObjectRef,
iterable: PyObjectRef,
}
impl PyValue for PyItertoolsFilterFalse {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct FilterFalseNewArgs {
#[pyarg(positional)]
@@ -921,7 +850,7 @@ mod decl {
#[pyattr]
#[pyclass(name = "accumulate")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsAccumulate {
iterable: PyObjectRef,
binop: Option<PyObjectRef>,
@@ -938,12 +867,6 @@ mod decl {
initial: OptionalOption<PyObjectRef>,
}
impl PyValue for PyItertoolsAccumulate {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl SlotConstructor for PyItertoolsAccumulate {
type Args = AccumulateArgs;
@@ -1013,18 +936,12 @@ mod decl {
#[pyattr]
#[pyclass(name = "tee")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsTee {
tee_data: PyRc<PyItertoolsTeeData>,
index: AtomicCell<usize>,
}
impl PyValue for PyItertoolsTee {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct TeeNewArgs {
#[pyarg(positional)]
@@ -1097,7 +1014,7 @@ mod decl {
#[pyattr]
#[pyclass(name = "product")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsProduct {
pools: Vec<Vec<PyObjectRef>>,
idxs: PyRwLock<Vec<usize>>,
@@ -1105,12 +1022,6 @@ mod decl {
stop: AtomicCell<bool>,
}
impl PyValue for PyItertoolsProduct {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct ProductArgs {
#[pyarg(named, optional)]
@@ -1200,7 +1111,7 @@ mod decl {
#[pyattr]
#[pyclass(name = "combinations")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsCombinations {
pool: Vec<PyObjectRef>,
indices: PyRwLock<Vec<usize>>,
@@ -1208,12 +1119,6 @@ mod decl {
exhausted: AtomicCell<bool>,
}
impl PyValue for PyItertoolsCombinations {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct CombinationsNewArgs {
#[pyarg(positional)]
@@ -1304,7 +1209,7 @@ mod decl {
#[pyattr]
#[pyclass(name = "combinations_with_replacement")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsCombinationsWithReplacement {
pool: Vec<PyObjectRef>,
indices: PyRwLock<Vec<usize>>,
@@ -1312,12 +1217,6 @@ mod decl {
exhausted: AtomicCell<bool>,
}
impl PyValue for PyItertoolsCombinationsWithReplacement {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl SlotConstructor for PyItertoolsCombinationsWithReplacement {
type Args = CombinationsNewArgs;
@@ -1395,7 +1294,7 @@ mod decl {
#[pyattr]
#[pyclass(name = "permutations")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsPermutations {
pool: Vec<PyObjectRef>, // Collected input iterable
indices: PyRwLock<Vec<usize>>, // One index per element in pool
@@ -1405,12 +1304,6 @@ mod decl {
exhausted: AtomicCell<bool>, // Set when the iterator is exhausted
}
impl PyValue for PyItertoolsPermutations {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[derive(FromArgs)]
struct PermutationsNewArgs {
#[pyarg(positional)]
@@ -1554,18 +1447,12 @@ mod decl {
#[pyattr]
#[pyclass(name = "zip_longest")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsZipLongest {
iterators: Vec<PyObjectRef>,
fillvalue: PyObjectRef,
}
impl PyValue for PyItertoolsZipLongest {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
impl PyItertoolsZipLongest {}
impl PyIter for PyItertoolsZipLongest {
@@ -1599,18 +1486,12 @@ mod decl {
#[pyattr]
#[pyclass(name = "pairwise")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItertoolsPairwise {
iterator: PyObjectRef,
old: PyRwLock<Option<PyObjectRef>>,
}
impl PyValue for PyItertoolsPairwise {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl SlotConstructor for PyItertoolsPairwise {
type Args = PyObjectRef;
+1 -7
View File
@@ -20,7 +20,7 @@ mod _json {
#[pyattr(name = "make_scanner")]
#[pyclass(name = "Scanner")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct JsonScanner {
strict: bool,
object_hook: Option<PyObjectRef>,
@@ -31,12 +31,6 @@ mod _json {
ctx: PyObjectRef,
}
impl PyValue for JsonScanner {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl SlotConstructor for JsonScanner {
type Args = PyObjectRef;
+3 -21
View File
@@ -436,17 +436,11 @@ mod _operator {
/// (r.name.first, r.name.last).
#[pyattr]
#[pyclass(name = "attrgetter")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyAttrGetter {
attrs: Vec<PyStrRef>,
}
impl PyValue for PyAttrGetter {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl(with(Callable))]
impl PyAttrGetter {
#[pyslot]
@@ -539,17 +533,11 @@ mod _operator {
/// After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])
#[pyattr]
#[pyclass(name = "itemgetter")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyItemGetter {
items: Vec<PyObjectRef>,
}
impl PyValue for PyItemGetter {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl(with(Callable))]
impl PyItemGetter {
#[pyslot]
@@ -614,18 +602,12 @@ mod _operator {
/// r.name('date', foo=1).
#[pyattr]
#[pyclass(name = "methodcaller")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyMethodCaller {
name: PyStrRef,
args: FuncArgs,
}
impl PyValue for PyMethodCaller {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl SlotConstructor for PyMethodCaller {
type Args = (PyObjectRef, FuncArgs);
+3 -21
View File
@@ -787,7 +787,7 @@ mod _os {
#[pyattr]
#[pyclass(name)]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct DirEntry {
entry: fs::DirEntry,
mode: OutputMode,
@@ -797,12 +797,6 @@ mod _os {
ino: AtomicCell<Option<u64>>,
}
impl PyValue for DirEntry {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl DirEntry {
#[pyproperty]
@@ -959,19 +953,13 @@ mod _os {
#[pyattr]
#[pyclass(name = "ScandirIter")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct ScandirIterator {
entries: PyRwLock<fs::ReadDir>,
exhausted: AtomicCell<bool>,
mode: OutputMode,
}
impl PyValue for ScandirIterator {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl(with(PyIter))]
impl ScandirIterator {
#[pymethod]
@@ -2486,17 +2474,11 @@ mod posix {
#[pyattr]
#[pyclass(name = "sched_param")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct SchedParam {
sched_priority: PyObjectRef,
}
impl PyValue for SchedParam {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl TryFromObject for SchedParam {
fn try_from_object(_vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
Ok(SchedParam {
+1 -7
View File
@@ -48,7 +48,7 @@ mod _pyexpat {
#[pyattr]
#[pyclass(name = "xmlparser", module = false)]
#[derive(Debug)]
#[derive(Debug, PyValue)]
pub struct PyExpatLikeXmlParser {
start_element: MutableObject,
end_element: MutableObject,
@@ -58,12 +58,6 @@ mod _pyexpat {
}
type PyExpatLikeXmlParserRef = PyRef<PyExpatLikeXmlParser>;
impl PyValue for PyExpatLikeXmlParser {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[inline]
fn invoke_handler<T>(vm: &VirtualMachine, handler: &MutableObject, args: T)
where
+2 -14
View File
@@ -789,7 +789,7 @@ pub(crate) mod _struct {
#[pyattr]
#[pyclass(name = "unpack_iterator")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct UnpackIterator {
format_spec: FormatSpec,
buffer: ArgBytesLike,
@@ -825,12 +825,6 @@ pub(crate) mod _struct {
}
}
impl PyValue for UnpackIterator {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl(with(PyIter))]
impl UnpackIterator {
#[pymethod(magic)]
@@ -870,18 +864,12 @@ pub(crate) mod _struct {
#[pyattr]
#[pyclass(name = "Struct")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyStruct {
spec: FormatSpec,
fmt_str: PyStrRef,
}
impl PyValue for PyStruct {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl SlotConstructor for PyStruct {
type Args = Either<PyStrRef, PyBytesRef>;
+1 -7
View File
@@ -56,17 +56,11 @@ mod _random {
#[pyattr]
#[pyclass(name = "Random")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyRandom {
rng: PyMutex<PyRng>,
}
impl PyValue for PyRandom {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl SlotConstructor for PyRandom {
type Args = OptionalOption<PyObjectRef>;
+5 -14
View File
@@ -17,7 +17,7 @@ use crate::vm::VirtualMachine;
use crate::{IntoPyObject, PyClassImpl, PyObjectRef, PyResult, PyValue, StaticType, TryFromObject};
#[pyclass(module = "re", name = "Pattern")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyPattern {
regex: Regex,
pattern: String,
@@ -62,14 +62,9 @@ impl PyRegexFlags {
}
}
impl PyValue for PyPattern {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
/// Inner data for a match object.
#[pyclass(module = "re", name = "Match")]
#[derive(PyValue)]
struct PyMatch {
haystack: PyStrRef,
captures: Vec<Option<Range<usize>>>,
@@ -81,12 +76,6 @@ impl fmt::Debug for PyMatch {
}
}
impl PyValue for PyMatch {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
// type PyPatternRef = PyRef<PyPattern>;
// type PyMatchRef = PyRef<PyMatch>;
@@ -246,7 +235,9 @@ fn do_split(
let split = output
.into_iter()
.map(|v| {
vm.unwrap_or_none(v.map(|v| vm.ctx.new_utf8_str(String::from_utf8_lossy(v).into_owned())))
vm.unwrap_or_none(
v.map(|v| vm.ctx.new_utf8_str(String::from_utf8_lossy(v).into_owned())),
)
})
.collect();
Ok(vm.ctx.new_list(split))
+1 -7
View File
@@ -264,18 +264,12 @@ mod decl {
use std::time;
#[pyclass(module = "select", name = "poll")]
#[derive(Default, Debug)]
#[derive(Default, Debug, PyValue)]
pub struct PyPoll {
// keep sorted
fds: PyMutex<Vec<pollfd>>,
}
impl PyValue for PyPoll {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[inline]
fn search(fds: &[pollfd], fd: i32) -> Result<usize, usize> {
fds.binary_search_by_key(&fd, |pfd| pfd.fd)
+1 -7
View File
@@ -142,7 +142,7 @@ impl Default for NullableSocket {
}
#[pyclass(module = "socket", name = "socket")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
pub struct PySocket {
kind: AtomicCell<i32>,
family: AtomicCell<i32>,
@@ -163,12 +163,6 @@ impl Default for PySocket {
}
}
impl PyValue for PySocket {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
pub type PySocketRef = PyRef<PySocket>;
#[cfg(windows)]
+3 -19
View File
@@ -122,7 +122,7 @@ mod _sre {
#[pyattr]
#[pyclass(name = "Pattern")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
pub(crate) struct Pattern {
pub pattern: PyObjectRef,
pub flags: SreFlag,
@@ -133,12 +133,6 @@ mod _sre {
pub isbytes: bool,
}
impl PyValue for Pattern {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl(with(Hashable, Comparable))]
impl Pattern {
fn with_str_drive<R, F: FnOnce(StrDrive) -> PyResult<R>>(
@@ -561,7 +555,7 @@ mod _sre {
#[pyattr]
#[pyclass(name = "Match")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
pub(crate) struct Match {
string: PyObjectRef,
pattern: PyRef<Pattern>,
@@ -570,11 +564,6 @@ mod _sre {
lastindex: isize,
regs: Vec<(isize, isize)>,
}
impl PyValue for Match {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl Match {
@@ -804,7 +793,7 @@ mod _sre {
#[pyattr]
#[pyclass(name = "SRE_Scanner")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct SreScanner {
pattern: PyRef<Pattern>,
string: PyObjectRef,
@@ -812,11 +801,6 @@ mod _sre {
end: usize,
must_advance: AtomicCell<bool>,
}
impl PyValue for SreScanner {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl SreScanner {
+2 -12
View File
@@ -248,6 +248,7 @@ fn _ssl_rand_pseudo_bytes(n: i32, vm: &VirtualMachine) -> PyResult<(Vec<u8>, boo
}
#[pyclass(module = "ssl", name = "_SSLContext")]
#[derive(PyValue)]
struct PySslContext {
ctx: PyRwLock<SslContextBuilder>,
check_hostname: AtomicCell<bool>,
@@ -260,12 +261,6 @@ impl fmt::Debug for PySslContext {
}
}
impl PyValue for PySslContext {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
fn builder_as_ctx(x: &SslContextBuilder) -> &ssl::SslContextRef {
unsafe { ssl::SslContextRef::from_ptr(x.as_ptr()) }
}
@@ -716,6 +711,7 @@ fn socket_closed_error(vm: &VirtualMachine) -> PyBaseExceptionRef {
}
#[pyclass(module = "ssl", name = "_SSLSocket")]
#[derive(PyValue)]
struct PySslSocket {
ctx: PyRef<PySslContext>,
stream: PyRwLock<ssl::SslStream<PySocketRef>>,
@@ -730,12 +726,6 @@ impl fmt::Debug for PySslSocket {
}
}
impl PyValue for PySslSocket {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl PySslSocket {
#[pyproperty]
+2 -12
View File
@@ -40,6 +40,7 @@ mod decl {
#[pyattr]
#[pyclass(name = "SymbolTable")]
#[derive(PyValue)]
struct PySymbolTable {
symtable: SymbolTable,
}
@@ -50,12 +51,6 @@ mod decl {
}
}
impl PyValue for PySymbolTable {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl PySymbolTable {
#[pymethod]
@@ -157,6 +152,7 @@ mod decl {
#[pyattr]
#[pyclass(name = "Symbol")]
#[derive(PyValue)]
struct PySymbol {
symbol: Symbol,
namespaces: Vec<SymbolTable>,
@@ -168,12 +164,6 @@ mod decl {
}
}
impl PyValue for PySymbol {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl PySymbol {
#[pymethod]
+3 -19
View File
@@ -96,17 +96,12 @@ macro_rules! repr_lock_impl {
}
#[pyclass(module = "thread", name = "lock")]
#[derive(PyValue)]
struct PyLock {
mu: RawMutex,
}
type PyLockRef = PyRef<PyLock>;
impl PyValue for PyLock {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl fmt::Debug for PyLock {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("PyLock")
@@ -150,16 +145,11 @@ impl PyLock {
pub type RawRMutex = RawReentrantMutex<RawMutex, RawThreadId>;
#[pyclass(module = "thread", name = "RLock")]
#[derive(PyValue)]
struct PyRLock {
mu: RawRMutex,
}
impl PyValue for PyRLock {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl fmt::Debug for PyRLock {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("PyRLock")
@@ -303,17 +293,11 @@ fn _thread_count(vm: &VirtualMachine) -> usize {
}
#[pyclass(module = "thread", name = "_local")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyLocal {
data: ThreadLocal<PyDictRef>,
}
impl PyValue for PyLocal {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl(with(SlotGetattro, SlotSetattro), flags(BASETYPE))]
impl PyLocal {
fn ldict(&self, vm: &VirtualMachine) -> PyDictRef {
+1 -7
View File
@@ -55,17 +55,11 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
}
#[pyclass(module = "unicodedata", name = "UCD")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyUCD {
unic_version: UnicodeVersion,
}
impl PyValue for PyUCD {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl Default for PyUCD {
#[inline(always)]
fn default() -> Self {
+1 -7
View File
@@ -13,7 +13,7 @@ use winapi::shared::winerror;
use winreg::{enums::RegType, RegKey, RegValue};
#[pyclass(module = "winreg", name = "HKEYType")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyHKEY {
key: PyRwLock<RegKey>,
}
@@ -22,12 +22,6 @@ type PyHKEYRef = PyRef<PyHKEY>;
// TODO: fix this
unsafe impl Sync for PyHKEY {}
impl PyValue for PyHKEY {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl PyHKEY {
fn new(key: RegKey) -> Self {
+2 -13
View File
@@ -270,18 +270,13 @@ mod decl {
}
#[pyattr]
#[pyclass(name = "Decompress")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyDecompress {
decompress: PyMutex<Decompress>,
eof: AtomicCell<bool>,
unused_data: PyMutex<PyBytesRef>,
unconsumed_tail: PyMutex<PyBytesRef>,
}
impl PyValue for PyDecompress {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl PyDecompress {
#[pyproperty]
@@ -441,17 +436,11 @@ mod decl {
#[pyattr]
#[pyclass(name = "Compress")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct PyCompress {
inner: PyMutex<CompressInner>,
}
impl PyValue for PyCompress {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl PyCompress {
#[pymethod]
+2 -14
View File
@@ -153,17 +153,11 @@ fn browser_cancel_animation_frame(id: i32, vm: &VirtualMachine) -> PyResult<()>
}
#[pyclass(module = "browser", name)]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct Document {
doc: web_sys::Document,
}
impl PyValue for Document {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl Document {
#[pymethod]
@@ -179,17 +173,11 @@ impl Document {
}
#[pyclass(module = "browser", name)]
#[derive(Debug)]
#[derive(Debug, PyValue)]
struct Element {
elem: web_sys::Element,
}
impl PyValue for Element {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl Element {
#[pymethod]
+4 -26
View File
@@ -51,18 +51,12 @@ extern "C" {
}
#[pyclass(module = "_js", name = "JSValue")]
#[derive(Debug)]
#[derive(Debug, PyValue)]
pub struct PyJsValue {
pub(crate) value: JsValue,
}
type PyJsValueRef = PyRef<PyJsValue>;
impl PyValue for PyJsValue {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl AsRef<JsValue> for PyJsValue {
fn as_ref(&self) -> &JsValue {
&self.value
@@ -281,6 +275,7 @@ struct NewObjectOptions {
type ClosureType = Closure<dyn FnMut(JsValue, Box<[JsValue]>) -> Result<JsValue, JsValue>>;
#[pyclass(module = "_js", name = "JSClosure")]
#[derive(PyValue)]
struct JsClosure {
closure: cell::RefCell<Option<(ClosureType, PyJsValueRef)>>,
destroyed: cell::Cell<bool>,
@@ -293,12 +288,6 @@ impl fmt::Debug for JsClosure {
}
}
impl PyValue for JsClosure {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl JsClosure {
fn new(obj: PyObjectRef, once: bool, vm: &VirtualMachine) -> Self {
@@ -380,7 +369,7 @@ impl JsClosure {
}
#[pyclass(module = "_js", name = "Promise")]
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PyValue)]
pub struct PyPromise {
value: PromiseKind,
}
@@ -394,12 +383,6 @@ enum PromiseKind {
PyRejected(PyBaseExceptionRef),
}
impl PyValue for PyPromise {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl]
impl PyPromise {
pub fn new(value: Promise) -> PyPromise {
@@ -548,6 +531,7 @@ impl PyPromise {
}
#[pyclass(module = "_js", name = "AwaitPromise")]
#[derive(PyValue)]
struct AwaitPromise {
obj: cell::Cell<Option<PyObjectRef>>,
}
@@ -558,12 +542,6 @@ impl fmt::Debug for AwaitPromise {
}
}
impl PyValue for AwaitPromise {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
#[pyimpl(with(PyIter))]
impl AwaitPromise {
#[pymethod]