cspell derive

This commit is contained in:
Jeong YunWon committed 2023-03-16 22:42:03 +09:00
1 parent 0b6546aa8d
commit 310a83427c
14 files changed
+98 -71

No files matched your search

+27 -1
View File
@@ -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": [
+1 -1
View File
@@ -38,7 +38,7 @@ static CARGO_MANIFEST_DIR: Lazy<PathBuf> = 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),
+11 -11
View File
@@ -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<TokenStream> {
};
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<TokenStream> {
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!(),
+10 -9
View File
@@ -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::<Item>)?;
for pyitem in pyitems.iter().rev() {
let r = pyitem.gen_impl_item(ImplItemArgs::<Item> {
let (py_items, cfgs) = attrs_to_content_items(attrs, impl_item_new::<Item>)?;
for py_item in py_items.iter().rev() {
let r = py_item.gen_impl_item(ImplItemArgs::<Item> {
item,
attrs,
context,
@@ -393,6 +393,7 @@ pub(crate) fn impl_define_exception(exc_def: PyExceptionDef) -> Result<TokenStre
// We need this method, because of how `CPython` copies `__init__`
// from `BaseException` in `SimpleExtendsException` macro.
// See: `(initproc)BaseException_init`
// spell-checker:ignore initproc
let init_method = match init {
Some(init_def) => 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<Item = NestedMeta>,
{
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)]",
)
})
}
+25 -25
View File
@@ -74,9 +74,9 @@ pub fn impl_pymodule(attr: AttributeArgs, module_item: Item) -> Result<TokenStre
continue;
}
let r = item.try_split_attr_mut(|attrs, item| {
let (pyitems, cfgs) = attrs_to_module_items(attrs, module_item_new)?;
for pyitem in pyitems.iter().rev() {
let r = pyitem.gen_module_item(ModuleItemArgs {
let (py_items, cfgs) = attrs_to_module_items(attrs, module_item_new)?;
for py_item in py_items.iter().rev() {
let r = py_item.gen_module_item(ModuleItemArgs {
item,
attrs,
context: &mut context,
@@ -145,20 +145,20 @@ pub fn impl_pymodule(attr: AttributeArgs, module_item: Item) -> Result<TokenStre
fn module_item_new(
index: usize,
attr_name: AttrName,
pyattrs: Vec<usize>,
py_attrs: Vec<usize>,
) -> Box<dyn ModuleItem<AttrName = AttrName>> {
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<AttrName>,
pyattrs: Vec<usize>,
py_attrs: Vec<usize>,
}
/// #[pyclass]
struct ClassItem {
inner: ContentItemInner<AttrName>,
pyattrs: Vec<usize>,
py_attrs: Vec<usize>,
}
/// #[pyattr]
struct AttributeItem {
inner: ContentItemInner<AttrName>,
pyattrs: Vec<usize>,
py_attrs: Vec<usize>,
}
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)?;
+1 -1
View File
@@ -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())
}
+4 -4
View File
@@ -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<dyn Error>> {
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}");
@@ -221,7 +221,7 @@ impl PyBuiltinMethod {
where
F: IntoPyNativeFunc<FKind>,
{
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<PyObjectRef>, (Option<PyObjectRef>, 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 {}
+2 -2
View File
@@ -562,10 +562,10 @@ impl PyBoundMethod {
&self,
vm: &VirtualMachine,
) -> (Option<PyObjectRef>, (PyObjectRef, Option<PyObjectRef>)) {
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)]
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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},
+4 -4
View File
@@ -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>],
)
+4 -4
View File
@@ -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);
+4 -4
View File
@@ -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<PyIntRef>,
// 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<F, FKind>(&self, name: impl Into<PyStr>, f: F) -> PyNativeFuncDef
pub fn make_func_def<F, FKind>(&self, name: impl Into<PyStr>, f: F) -> PyNativeFuncDef
where
F: IntoPyNativeFunc<FKind>,
{
@@ -505,7 +505,7 @@ impl Context {
where
F: IntoPyNativeFunc<FKind>,
{
self.make_funcdef(name, f).build_function(self)
self.make_func_def(name, f).build_function(self)
}
pub fn new_method<F, FKind>(