From 310a83427c8faae615934055a5a8f3a408895065 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 16 Mar 2023 21:52:38 +0900 Subject: [PATCH] cspell derive --- .cspell.json | 28 ++++++++++- derive-impl/src/compile_bytecode.rs | 2 +- derive-impl/src/from_args.rs | 22 ++++---- derive-impl/src/pyclass.rs | 19 +++---- derive-impl/src/pymodule.rs | 50 +++++++++---------- derive-impl/src/util.rs | 2 +- examples/dis.rs | 8 +-- .../{builtinfunc.rs => builtin_func.rs} | 6 +-- vm/src/builtins/function.rs | 4 +- vm/src/builtins/mod.rs | 2 +- vm/src/builtins/staticmethod.rs | 2 +- vm/src/macros.rs | 8 +-- vm/src/types/zoo.rs | 8 +-- vm/src/vm/context.rs | 8 +-- 14 files changed, 98 insertions(+), 71 deletions(-) rename vm/src/builtins/{builtinfunc.rs => builtin_func.rs} (97%) diff --git a/.cspell.json b/.cspell.json index ff2ab3435..581666910 100644 --- a/.cspell.json +++ b/.cspell.json @@ -32,17 +32,23 @@ "cstring", "flate2", "hasher", + "idents", "indexmap", "insta", "keccak", "lalrpop", + "libc", "Manually", + "maplit", "memmap", + "metas", "peekable", "prepended", + "punct", "rustc", "rustfmt", "splitn", + "trai", "unic", "unistd", // Python @@ -52,6 +58,7 @@ "basicsize", "cformat", "classcell", + "codepoint", "cpython", "defaultaction", "descr", @@ -68,10 +75,13 @@ "fstrings", "genexpr", "getattro", + "getformat", + "getnewargs", "getweakrefcount", "getweakrefs", "idiv", "impls", + "instancecheck", "instanceof", "itemsize", "iternext", @@ -103,6 +113,7 @@ "setcomp", "stacklevel", "subclasscheck", + "subclasshook", "unionable", "unraisablehook", "vararg", @@ -113,15 +124,20 @@ "weakproxy", "xopts", // RustPython + "baseclass", "Bytecode", + "cfgs", "codegen", "dedentations", "dedents", "deduped", + "downcasted", "dumpable", "GetSet", + "internable", "makeunicodedata", "miri", + "notrace", "pyarg", "pyarg", "pyargs", @@ -133,18 +149,25 @@ "PyFunction", "pygetset", "pyimpl", + "pymember", "PyMethod", "PyModule", + "pyname", "pyobj", "PyObject", + "pypayload", "PyProperty", "pyref", "PyResult", "pyslot", "PyStaticMethod", "pystr", + "pystruct", + "pystructseq", + "pytrace", "richcompare", "RustPython", + "struc", "tracebacks", "typealiases", "Unconstructible", @@ -158,6 +181,8 @@ "asdl", "asname", "augassign", + "badsyntax", + "basetype", "boolop", "bxor", "cellarg", @@ -190,7 +215,8 @@ "unparser", "VARKEYWORDS", "varkwarg", - "withitem" + "withitem", + "withs" ], // flagWords - list of words to be always considered incorrect "flagWords": [ diff --git a/derive-impl/src/compile_bytecode.rs b/derive-impl/src/compile_bytecode.rs index 30962326e..62bd52d5b 100644 --- a/derive-impl/src/compile_bytecode.rs +++ b/derive-impl/src/compile_bytecode.rs @@ -38,7 +38,7 @@ static CARGO_MANIFEST_DIR: Lazy = Lazy::new(|| { enum CompilationSourceKind { /// Source is a File (Path) File(PathBuf), - /// Direct Raw sourcecode + /// Direct Raw source code SourceCode(String), /// Source is a directory Dir(PathBuf), diff --git a/derive-impl/src/from_args.rs b/derive-impl/src/from_args.rs index 5b3b1e637..48bcd4fe2 100644 --- a/derive-impl/src/from_args.rs +++ b/derive-impl/src/from_args.rs @@ -86,7 +86,7 @@ impl ArgAttribute { self.default = Some(None); } } else { - bail_span!(path, "Unrecognised pyarg attribute"); + bail_span!(path, "Unrecognized pyarg attribute"); } } NestedMeta::Meta(Meta::NameValue(name_value)) => { @@ -109,10 +109,10 @@ impl ArgAttribute { _ => bail_span!(name_value, "Expected string value for name argument"), } } else { - bail_span!(name_value, "Unrecognised pyarg attribute"); + bail_span!(name_value, "Unrecognized pyarg attribute"); } } - _ => bail_span!(arg, "Unrecognised pyarg attribute"), + _ => bail_span!(arg, "Unrecognized pyarg attribute"), } Ok(()) @@ -138,24 +138,24 @@ fn generate_field((i, field): (usize, &Field)) -> Result { }; let name = field.ident.as_ref(); - let namestring = name.map(Ident::to_string); - if matches!(&namestring, Some(s) if s.starts_with("_phantom")) { + let name_string = name.map(Ident::to_string); + if matches!(&name_string, Some(s) if s.starts_with("_phantom")) { return Ok(quote! { #name: ::std::marker::PhantomData, }); } - let fieldname = match name { + let field_name = match name { Some(id) => id.to_token_stream(), None => syn::Index::from(i).into_token_stream(), }; if let ParameterKind::Flatten = attr.kind { return Ok(quote! { - #fieldname: ::rustpython_vm::function::FromArgs::from_args(vm, args)?, + #field_name: ::rustpython_vm::function::FromArgs::from_args(vm, args)?, }); } let pyname = attr .name - .or(namestring) + .or(name_string) .ok_or_else(|| err_span!(field, "field in tuple struct must have name attribute"))?; let middle = quote! { .map(|x| ::rustpython_vm::convert::TryFromObject::try_from_object(vm, x)).transpose()? @@ -184,17 +184,17 @@ fn generate_field((i, field): (usize, &Field)) -> Result { let file_output = match attr.kind { ParameterKind::PositionalOnly => { quote! { - #fieldname: args.take_positional()#middle #ending, + #field_name: args.take_positional()#middle #ending, } } ParameterKind::PositionalOrKeyword => { quote! { - #fieldname: args.take_positional_keyword(#pyname)#middle #ending, + #field_name: args.take_positional_keyword(#pyname)#middle #ending, } } ParameterKind::KeywordOnly => { quote! { - #fieldname: args.take_keyword(#pyname)#middle #ending, + #field_name: args.take_keyword(#pyname)#middle #ending, } } ParameterKind::Flatten => unreachable!(), diff --git a/derive-impl/src/pyclass.rs b/derive-impl/src/pyclass.rs index 45c366746..92fd9e5bc 100644 --- a/derive-impl/src/pyclass.rs +++ b/derive-impl/src/pyclass.rs @@ -81,9 +81,9 @@ fn extract_items_into_context<'a, Item>( { for item in items { let r = item.try_split_attr_mut(|attrs, item| { - let (pyitems, cfgs) = attrs_to_content_items(attrs, impl_item_new::)?; - for pyitem in pyitems.iter().rev() { - let r = pyitem.gen_impl_item(ImplItemArgs:: { + let (py_items, cfgs) = attrs_to_content_items(attrs, impl_item_new::)?; + for py_item in py_items.iter().rev() { + let r = py_item.gen_impl_item(ImplItemArgs:: { item, attrs, context, @@ -393,6 +393,7 @@ pub(crate) fn impl_define_exception(exc_def: PyExceptionDef) -> Result quote! { #init_def(zelf, args, vm) }, None => quote! { #base_class::init(zelf, args, vm) }, @@ -553,7 +554,7 @@ where quote_spanned! { ident.span() => class.set_attr( ctx.names.#name_ident, - ctx.make_funcdef(#py_name, Self::#ident) + ctx.make_func_def(#py_name, Self::#ident) #doc #build_func .into(), @@ -563,7 +564,7 @@ where quote_spanned! { ident.span() => class.set_str_attr( #py_name, - ctx.make_funcdef(#py_name, Self::#ident) + ctx.make_func_def(#py_name, Self::#ident) #doc #build_func, ctx, @@ -1048,8 +1049,8 @@ impl ItemMeta for SlotItemMeta { where I: std::iter::Iterator, { - let meta_map = if let Some(nmeta) = nested.next() { - match nmeta { + let meta_map = if let Some(nested_meta) = nested.next() { + match nested_meta { NestedMeta::Meta(meta) => { Some([("name".to_owned(), (0, meta))].iter().cloned().collect()) } @@ -1059,7 +1060,7 @@ impl ItemMeta for SlotItemMeta { Some(HashMap::default()) }; let (Some(meta_map), None) = (meta_map, nested.next()) else { - bail_span!(meta_ident, "#[pyslot] must be of the form #[pyslot] or #[pyslot(slotname)]") + bail_span!(meta_ident, "#[pyslot] must be of the form #[pyslot] or #[pyslot(slot_name)]") }; Ok(Self::from_inner(ItemMetaInner { item_ident, @@ -1096,7 +1097,7 @@ impl SlotItemMeta { slot_name.ok_or_else(|| { err_span!( inner.meta_ident, - "#[pyslot] must be of the form #[pyslot] or #[pyslot(slotname)]", + "#[pyslot] must be of the form #[pyslot] or #[pyslot(slot_name)]", ) }) } diff --git a/derive-impl/src/pymodule.rs b/derive-impl/src/pymodule.rs index 74323304a..63bdc33ea 100644 --- a/derive-impl/src/pymodule.rs +++ b/derive-impl/src/pymodule.rs @@ -74,9 +74,9 @@ pub fn impl_pymodule(attr: AttributeArgs, module_item: Item) -> Result Result, + py_attrs: Vec, ) -> Box> { match attr_name { AttrName::Function => Box::new(FunctionItem { inner: ContentItemInner { index, attr_name }, - pyattrs, + py_attrs, }), AttrName::Attr => Box::new(AttributeItem { inner: ContentItemInner { index, attr_name }, - pyattrs, + py_attrs, }), AttrName::Class => Box::new(ClassItem { inner: ContentItemInner { index, attr_name }, - pyattrs, + py_attrs, }), } } @@ -186,7 +186,7 @@ where } let mut closed = false; - let mut pyattrs = Vec::new(); + let mut py_attrs = Vec::new(); for (i, attr) in iter { // take py items but no cfgs let attr_name = if let Some(ident) = attr.get_ident() { @@ -218,16 +218,16 @@ where "#[pyattr] must be placed on top of other #[py*] items", ) } - pyattrs.push(i); + py_attrs.push(i); continue; } - if pyattrs.is_empty() { + if py_attrs.is_empty() { result.push(item_new(i, attr_name, Vec::new())); } else { match attr_name { AttrName::Class | AttrName::Function => { - result.push(item_new(i, attr_name, pyattrs.clone())); + result.push(item_new(i, attr_name, py_attrs.clone())); } _ => { bail_span!( @@ -236,14 +236,14 @@ where ) } } - pyattrs.clear(); + py_attrs.clear(); closed = true; } } - if let Some(last) = pyattrs.pop() { + if let Some(last) = py_attrs.pop() { assert!(!closed); - result.push(item_new(last, AttrName::Attr, pyattrs)); + result.push(item_new(last, AttrName::Attr, py_attrs)); } Ok((result, cfgs)) } @@ -251,19 +251,19 @@ where /// #[pyfunction] struct FunctionItem { inner: ContentItemInner, - pyattrs: Vec, + py_attrs: Vec, } /// #[pyclass] struct ClassItem { inner: ContentItemInner, - pyattrs: Vec, + py_attrs: Vec, } /// #[pyattr] struct AttributeItem { inner: ContentItemInner, - pyattrs: Vec, + py_attrs: Vec, } impl ContentItem for FunctionItem { @@ -334,14 +334,14 @@ impl ModuleItem for FunctionItem { }; let doc = quote!(.with_doc(#doc.to_owned(), &vm.ctx)); let new_func = quote_spanned!(ident.span()=> - vm.ctx.make_funcdef(#py_name, #ident) + vm.ctx.make_func_def(#py_name, #ident) #doc .into_function() .with_module(vm.new_pyobj(#module.to_owned())) .into_ref(&vm.ctx) ); - if self.pyattrs.is_empty() { + if self.py_attrs.is_empty() { ( quote_spanned! { ident.span() => { let func = #new_func; @@ -352,7 +352,7 @@ impl ModuleItem for FunctionItem { } else { let mut py_names = HashSet::new(); py_names.insert(py_name); - for attr_index in self.pyattrs.iter().rev() { + for attr_index in self.py_attrs.iter().rev() { let mut loop_unit = || { let attr_attr = args.attrs.remove(*attr_index); let item_meta = SimpleItemMeta::from_attr(ident.clone(), &attr_attr)?; @@ -402,7 +402,7 @@ impl ModuleItem for ClassItem { let (class_name, class_new) = { let class_attr = &mut args.attrs[self.inner.index]; let no_attr = class_attr.try_remove_name("no_attr")?; - if self.pyattrs.is_empty() { + if self.py_attrs.is_empty() { // check no_attr before ClassItemMeta::from_attr if no_attr.is_none() { bail_span!( @@ -439,7 +439,7 @@ impl ModuleItem for ClassItem { }; let mut py_names = Vec::new(); - for attr_index in self.pyattrs.iter().rev() { + for attr_index in self.py_attrs.iter().rev() { let mut loop_unit = || { let attr_attr = args.attrs.remove(*attr_index); let item_meta = SimpleItemMeta::from_attr(ident.clone(), &attr_attr)?; @@ -540,7 +540,7 @@ impl ModuleItem for AttributeItem { ) } Item::Use(item) => { - if !self.pyattrs.is_empty() { + if !self.py_attrs.is_empty() { return Err(self .new_syn_error(item.span(), "Only single #[pyattr] is allowed for `use`")); } @@ -578,7 +578,7 @@ impl ModuleItem for AttributeItem { } }; - let (tokens, py_names) = if self.pyattrs.is_empty() { + let (tokens, py_names) = if self.py_attrs.is_empty() { ( quote_spanned! { ident.span() => { #let_obj @@ -588,7 +588,7 @@ impl ModuleItem for AttributeItem { ) } else { let mut names = vec![py_name]; - for attr_index in self.pyattrs.iter().rev() { + for attr_index in self.py_attrs.iter().rev() { let mut loop_unit = || { let attr_attr = args.attrs.remove(*attr_index); let item_meta = AttrItemMeta::from_attr(ident.clone(), &attr_attr)?; diff --git a/derive-impl/src/util.rs b/derive-impl/src/util.rs index b2fd5e782..92bb4629f 100644 --- a/derive-impl/src/util.rs +++ b/derive-impl/src/util.rs @@ -423,7 +423,7 @@ impl AttributeExt for Attribute { let has_name = list .nested .iter() - .any(|nmeta| nmeta.get_path().map_or(false, |p| p.is_ident(name))); + .any(|nested_meta| nested_meta.get_path().map_or(false, |p| p.is_ident(name))); if !has_name { list.nested.push(new_item()) } diff --git a/examples/dis.rs b/examples/dis.rs index cde64c42e..0b1e7c0d3 100644 --- a/examples/dis.rs +++ b/examples/dis.rs @@ -57,7 +57,7 @@ fn main() { let matches = app.get_matches(); let mode = matches.value_of_lossy("mode").unwrap().parse().unwrap(); - let expand_codeobjects = !matches.is_present("no_expand"); + let expand_code_objects = !matches.is_present("no_expand"); let optimize = matches.occurrences_of("optimize") as u8; let scripts = matches.values_of_os("scripts").unwrap(); @@ -68,7 +68,7 @@ fn main() { for script in scripts.map(Path::new) { if script.exists() && script.is_file() { - let res = display_script(script, mode, opts.clone(), expand_codeobjects); + let res = display_script(script, mode, opts.clone(), expand_code_objects); if let Err(e) = res { error!("Error while compiling {:?}: {}", script, e); } @@ -82,12 +82,12 @@ fn display_script( path: &Path, mode: compiler::Mode, opts: compiler::CompileOpts, - expand_codeobjects: bool, + expand_code_objects: bool, ) -> Result<(), Box> { let source = fs::read_to_string(path)?; let code = compiler::compile(&source, mode, path.to_string_lossy().into_owned(), opts)?; println!("{}:", path.display()); - if expand_codeobjects { + if expand_code_objects { println!("{}", code.display_expand_code_objects()); } else { println!("{code}"); diff --git a/vm/src/builtins/builtinfunc.rs b/vm/src/builtins/builtin_func.rs similarity index 97% rename from vm/src/builtins/builtinfunc.rs rename to vm/src/builtins/builtin_func.rs index 3dea2fa87..8d694abaa 100644 --- a/vm/src/builtins/builtinfunc.rs +++ b/vm/src/builtins/builtin_func.rs @@ -221,7 +221,7 @@ impl PyBuiltinMethod { where F: IntoPyNativeFunc, { - ctx.make_funcdef(name, f).build_method(ctx, class) + ctx.make_func_def(name, f).build_method(ctx, class) } } @@ -259,9 +259,9 @@ impl PyBuiltinMethod { &self, vm: &VirtualMachine, ) -> (Option, (Option, PyStrRef)) { - let builtinfunc_getattr = vm.builtins.get_attr("getattr", vm).ok(); + let builtins_getattr = vm.builtins.get_attr("getattr", vm).ok(); let classname = vm.builtins.get_attr(self.class.name().to_string(), vm).ok(); - (builtinfunc_getattr, (classname, self.value.name.clone())) + (builtins_getattr, (classname, self.value.name.clone())) } } impl Unconstructible for PyBuiltinMethod {} diff --git a/vm/src/builtins/function.rs b/vm/src/builtins/function.rs index 6c476b55a..d6d85fead 100644 --- a/vm/src/builtins/function.rs +++ b/vm/src/builtins/function.rs @@ -562,10 +562,10 @@ impl PyBoundMethod { &self, vm: &VirtualMachine, ) -> (Option, (PyObjectRef, Option)) { - let builtinfunc_getattr = vm.builtins.get_attr("getattr", vm).ok(); + let builtins_getattr = vm.builtins.get_attr("getattr", vm).ok(); let funcself = self.object.clone(); let funcname = self.function.get_attr("__name__", vm).ok(); - (builtinfunc_getattr, (funcself, funcname)) + (builtins_getattr, (funcself, funcname)) } #[pygetset(magic)] diff --git a/vm/src/builtins/mod.rs b/vm/src/builtins/mod.rs index 795daaf89..f068e94a9 100644 --- a/vm/src/builtins/mod.rs +++ b/vm/src/builtins/mod.rs @@ -4,7 +4,7 @@ pub(crate) mod asyncgenerator; pub use asyncgenerator::PyAsyncGen; -pub(crate) mod builtinfunc; +pub(crate) mod builtin_func; pub(crate) mod bytearray; pub use bytearray::PyByteArray; pub(crate) mod bytes; diff --git a/vm/src/builtins/staticmethod.rs b/vm/src/builtins/staticmethod.rs index 47630360c..76144ce63 100644 --- a/vm/src/builtins/staticmethod.rs +++ b/vm/src/builtins/staticmethod.rs @@ -1,6 +1,6 @@ use super::{PyStr, PyType, PyTypeRef}; use crate::{ - builtins::builtinfunc::PyBuiltinMethod, + builtins::builtin_func::PyBuiltinMethod, class::PyClassImpl, common::lock::PyMutex, function::{FuncArgs, IntoPyNativeFunc}, diff --git a/vm/src/macros.rs b/vm/src/macros.rs index a31cf83c6..24a558528 100644 --- a/vm/src/macros.rs +++ b/vm/src/macros.rs @@ -58,8 +58,8 @@ macro_rules! py_namespace { /// Macro to match on the built-in class of a Python object. /// -/// Like `match`, `match_class!` must be exhaustive, so a default arm with -/// the uncasted object is required. +/// Like `match`, `match_class!` must be exhaustive, so a default arm without +/// casting is required. /// /// # Examples /// @@ -184,7 +184,7 @@ macro_rules! identifier( }; ); -/// Super detailed logging. Might soon overflow your logbuffers +/// Super detailed logging. Might soon overflow your log buffers /// Default, this logging is discarded, except when a the `vm-tracing-logging` /// build feature is enabled. macro_rules! vm_trace { @@ -218,7 +218,7 @@ macro_rules! named_function { #[allow(unused_variables)] // weird lint, something to do with paste probably let ctx: &$crate::Context = &$ctx; $crate::__exports::paste::expr! { - ctx.make_funcdef( + ctx.make_func_def( stringify!($func), [<$module _ $func>], ) diff --git a/vm/src/types/zoo.rs b/vm/src/types/zoo.rs index eb3f3f05f..66cb2eff8 100644 --- a/vm/src/types/zoo.rs +++ b/vm/src/types/zoo.rs @@ -1,6 +1,6 @@ use crate::{ builtins::{ - asyncgenerator, bool_, builtinfunc, bytearray, bytes, classmethod, code, complex, + asyncgenerator, bool_, builtin_func, bytearray, bytes, classmethod, code, complex, coroutine, descriptor, dict, enumerate, filter, float, frame, function, generator, genericalias, getset, int, iter, list, map, mappingproxy, memory, module, namespace, object, property, pystr, range, set, singletons, slice, staticmethod, super_, traceback, @@ -134,7 +134,7 @@ impl TypeZoo { 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(), + builtin_function_or_method_type: builtin_func::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(), @@ -171,7 +171,7 @@ impl TypeZoo { 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(), + method_descriptor_type: builtin_func::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(), @@ -189,7 +189,7 @@ impl TypeZoo { set::init(context); tuple::init(context); dict::init(context); - builtinfunc::init(context); + builtin_func::init(context); function::init(context); staticmethod::init(context); classmethod::init(context); diff --git a/vm/src/vm/context.rs b/vm/src/vm/context.rs index 95b8da260..42c33caff 100644 --- a/vm/src/vm/context.rs +++ b/vm/src/vm/context.rs @@ -1,6 +1,6 @@ use crate::{ builtins::{ - builtinfunc::{PyBuiltinFunction, PyBuiltinMethod, PyNativeFuncDef}, + builtin_func::{PyBuiltinFunction, PyBuiltinMethod, PyNativeFuncDef}, bytes, code::{self, PyCode}, descriptor::{ @@ -43,7 +43,7 @@ pub struct Context { pub types: TypeZoo, pub exceptions: exceptions::ExceptionZoo, pub int_cache_pool: Vec, - // there should only be exact objects of str in here, no non-strs and no subclasses + // there should only be exact objects of str in here, no non-str objects and no subclasses pub(crate) string_pool: StringPool, pub(crate) slot_new_wrapper: PyObjectRef, pub names: ConstName, @@ -461,7 +461,7 @@ impl Context { } #[inline] - pub fn make_funcdef(&self, name: impl Into, f: F) -> PyNativeFuncDef + pub fn make_func_def(&self, name: impl Into, f: F) -> PyNativeFuncDef where F: IntoPyNativeFunc, { @@ -505,7 +505,7 @@ impl Context { where F: IntoPyNativeFunc, { - self.make_funcdef(name, f).build_function(self) + self.make_func_def(name, f).build_function(self) } pub fn new_method(