Merge pull request #4698 from youknowone/cspell

Update cspell
This commit is contained in:
Jeong YunWon
2023-03-16 23:15:37 +09:00
committed by GitHub
49 changed files with 497 additions and 458 deletions

View File

@@ -26,120 +26,197 @@
"words": [
// Rust
"ahash",
"bitflags",
"bindgen",
"cstring",
"bitflags",
"chrono",
"cstring",
"flate2",
"hasher",
"idents",
"indexmap",
"insta",
"peekable",
"keccak",
"lalrpop",
"memmap",
"libc",
"Manually",
"maplit",
"memmap",
"metas",
"peekable",
"prepended",
"punct",
"rustc",
"rustfmt",
"splitn",
"unistd",
"trai",
"unic",
"unistd",
// Python
"cformat",
"cpython",
"fspath",
"kwarg",
"kwargs",
"vararg",
"varargs",
"metaclass",
"metaclasses",
"fstring",
"fstrings",
"docstring",
"docstrings",
"fileencoding",
"linearization",
"linearize",
"PYTHONDEBUG",
"PYTHONINSPECT",
"PYTHONPATH",
"PYTHONHOME",
"PYTHONPATH",
"PYTHONVERBOSE",
"PYTHONOPTIMIZE",
"PYTHONWARNINGS",
"basicsize",
"itemsize",
"origname",
"getattro",
"setattro",
"iternext",
"maxsplit",
"fdel",
"subclasscheck",
"qualname",
"eventmask",
"instanceof",
"abstractmethods",
"aiter",
"anext",
"rdiv",
"idiv",
"ndim",
"unionable",
"varnames",
"getweakrefs",
"getweakrefcount",
"stacklevel",
"MemoryView",
"metatype",
"warningregistry",
"basicsize",
"cformat",
"classcell",
"codepoint",
"cpython",
"defaultaction",
"unraisablehook",
"descr",
"xopts",
"dictcomp",
"docstring",
"docstrings",
"dunder",
"eventmask",
"fdel",
"fileencoding",
"finallyhandler",
"fspath",
"fstring",
"fstrings",
"genexpr",
"getattro",
"getformat",
"getnewargs",
"getweakrefcount",
"getweakrefs",
"idiv",
"impls",
"instancecheck",
"instanceof",
"itemsize",
"iternext",
"kwarg",
"kwargs",
"linearization",
"linearize",
"listcomp",
"mappingproxy",
"maxsplit",
"MemoryView",
"metaclass",
"metaclasses",
"metatype",
"ndim",
"nonbytes",
"origname",
"PYTHONDEBUG",
"PYTHONHOME",
"PYTHONINSPECT",
"PYTHONOPTIMIZE",
"PYTHONPATH",
"PYTHONPATH",
"PYTHONVERBOSE",
"PYTHONWARNINGS",
"qualname",
"rdiv",
"setattro",
"setcomp",
"stacklevel",
"subclasscheck",
"subclasshook",
"unionable",
"unraisablehook",
"vararg",
"varargs",
"varnames",
"warningregistry",
"warnopts",
"weakproxy",
"mappingproxy",
"xopts",
// RustPython
"RustPython",
"baseclass",
"Bytecode",
"cfgs",
"codegen",
"dedentations",
"dedents",
"deduped",
"downcasted",
"dumpable",
"GetSet",
"internable",
"makeunicodedata",
"miri",
"notrace",
"pyarg",
"pyarg",
"pyargs",
"pygetset",
"pyobj",
"pystr",
"pyc",
"pyref",
"pyslot",
"PyFunction",
"PyMethod",
"PyClassMethod",
"PyStaticMethod",
"PyProperty",
"PyClass",
"pyimpl",
"pyarg",
"PyModule",
"PyAttr",
"PyResult",
"PyObject",
"pyc",
"PyClass",
"PyClassMethod",
"PyException",
"GetSet",
"zelf",
"wasi",
"Bytecode",
"PyFunction",
"pygetset",
"pyimpl",
"pymember",
"PyMethod",
"PyModule",
"pyname",
"pyobj",
"PyObject",
"pypayload",
"PyProperty",
"pyref",
"PyResult",
"pyslot",
"PyStaticMethod",
"pystr",
"pystruct",
"pystructseq",
"pytrace",
"richcompare",
"makeunicodedata",
"unhashable",
"unraisable",
"RustPython",
"struc",
"tracebacks",
"typealiases",
"Unconstructible",
"posonlyargs",
"kwonlyargs",
"unhashable",
"uninit",
"miri",
"unraisable",
"wasi",
"zelf",
// cpython
"linearise",
"argtypes",
"asdl",
"asname",
"augassign",
"badsyntax",
"basetype",
"boolop",
"bxor",
"cellarg",
"cellvar",
"cellvars",
"cmpop",
"dictoffset",
"elts",
"excepthandler",
"finalbody",
"freevar",
"freevars",
"fromlist",
"heaptype",
"IMMUTABLETYPE"
"IMMUTABLETYPE",
"kwonlyarg",
"kwonlyargs",
"linearise",
"maxdepth",
"mult",
"nkwargs",
"orelse",
"patma",
"posonlyarg",
"posonlyargs",
"prec",
"stackdepth",
"unaryop",
"unparse",
"unparser",
"VARKEYWORDS",
"varkwarg",
"withitem",
"withs"
],
// flagWords - list of words to be always considered incorrect
"flagWords": [

View File

@@ -127,7 +127,7 @@ jobs:
echo "OPENSSL_DIR=C:\Program Files\OpenSSL-Win64" >>$GITHUB_ENV
if: runner.os == 'Windows'
- name: Set up the Mac environment
run: brew install autoconf automake libtool openssl@3
run: brew install autoconf automake libtool
if: runner.os == 'macOS'
- uses: Swatinem/rust-cache@v2

View File

@@ -48,10 +48,10 @@ impl<'a> Unparser<'a> {
}
fn unparse_expr<U>(&mut self, ast: &Expr<U>, level: u8) -> fmt::Result {
macro_rules! opprec {
($opty:ident, $x:expr, $enu:path, $($var:ident($op:literal, $prec:ident)),*$(,)?) => {
macro_rules! op_prec {
($op_ty:ident, $x:expr, $enu:path, $($var:ident($op:literal, $prec:ident)),*$(,)?) => {
match $x {
$(<$enu>::$var => (opprec!(@space $opty, $op), precedence::$prec),)*
$(<$enu>::$var => (op_prec!(@space $op_ty, $op), precedence::$prec),)*
}
};
(@space bin, $op:literal) => {
@@ -72,7 +72,7 @@ impl<'a> Unparser<'a> {
}
match &ast.node {
ExprKind::BoolOp { op, values } => {
let (op, prec) = opprec!(bin, op, Boolop, And("and", AND), Or("or", OR));
let (op, prec) = op_prec!(bin, op, Boolop, And("and", AND), Or("or", OR));
group_if!(prec, {
let mut first = true;
for val in values {
@@ -89,8 +89,8 @@ impl<'a> Unparser<'a> {
})
}
ExprKind::BinOp { left, op, right } => {
let rassoc = matches!(op, Operator::Pow);
let (op, prec) = opprec!(
let right_associative = matches!(op, Operator::Pow);
let (op, prec) = op_prec!(
bin,
op,
Operator,
@@ -109,13 +109,13 @@ impl<'a> Unparser<'a> {
FloorDiv("//", TERM),
);
group_if!(prec, {
self.unparse_expr(left, prec + rassoc as u8)?;
self.unparse_expr(left, prec + right_associative as u8)?;
self.p(op)?;
self.unparse_expr(right, prec + !rassoc as u8)?;
self.unparse_expr(right, prec + !right_associative as u8)?;
})
}
ExprKind::UnaryOp { op, operand } => {
let (op, prec) = opprec!(
let (op, prec) = op_prec!(
un,
op,
crate::Unaryop,
@@ -131,8 +131,8 @@ impl<'a> Unparser<'a> {
}
ExprKind::Lambda { args, body } => {
group_if!(precedence::TEST, {
let npos = args.args.len() + args.posonlyargs.len();
self.p(if npos > 0 { "lambda " } else { "lambda" })?;
let pos = args.args.len() + args.posonlyargs.len();
self.p(if pos > 0 { "lambda " } else { "lambda" })?;
self.unparse_args(args)?;
write!(self, ": {}", **body)?;
})
@@ -260,7 +260,7 @@ impl<'a> Unparser<'a> {
[],
) = (&**args, &**keywords)
{
// make sure a single genexp doesn't get double parens
// make sure a single genexpr doesn't get double parens
self.unparse_expr(elt, precedence::TEST)?;
self.unparse_comp(generators)?;
} else {
@@ -287,7 +287,7 @@ impl<'a> Unparser<'a> {
conversion,
format_spec,
} => self.unparse_formatted(value, *conversion, format_spec.as_deref())?,
ExprKind::JoinedStr { values } => self.unparse_joinedstr(values, false)?,
ExprKind::JoinedStr { values } => self.unparse_joined_str(values, false)?,
ExprKind::Constant { value, kind } => {
if let Some(kind) = kind {
self.p(kind)?;
@@ -490,7 +490,7 @@ impl<'a> Unparser<'a> {
unreachable!()
}
}
ExprKind::JoinedStr { values } => self.unparse_joinedstr(values, is_spec),
ExprKind::JoinedStr { values } => self.unparse_joined_str(values, is_spec),
ExprKind::FormattedValue {
value,
conversion,
@@ -505,7 +505,7 @@ impl<'a> Unparser<'a> {
self.p(&s)
}
fn unparse_joinedstr<U>(&mut self, values: &[Expr<U>], is_spec: bool) -> fmt::Result {
fn unparse_joined_str<U>(&mut self, values: &[Expr<U>], is_spec: bool) -> fmt::Result {
if is_spec {
self.unparse_fstring_body(values, is_spec)
} else {

View File

@@ -189,14 +189,14 @@ macro_rules! emit {
($c:expr, Instruction::$op:ident { $arg:ident$(,)? }$(,)?) => {
$c.emit_arg($arg, |x| Instruction::$op { $arg: x })
};
($c:expr, Instruction::$op:ident { $arg:ident : $argval:expr $(,)? }$(,)?) => {
$c.emit_arg($argval, |x| Instruction::$op { $arg: x })
($c:expr, Instruction::$op:ident { $arg:ident : $arg_val:expr $(,)? }$(,)?) => {
$c.emit_arg($arg_val, |x| Instruction::$op { $arg: x })
};
($c:expr, Instruction::$op:ident( $argval:expr $(,)? )$(,)?) => {
$c.emit_arg($argval, Instruction::$op)
($c:expr, Instruction::$op:ident( $arg_val:expr $(,)? )$(,)?) => {
$c.emit_arg($arg_val, Instruction::$op)
};
($c:expr, Instruction::$op:ident$(,)?) => {
$c.emit_noarg(Instruction::$op)
$c.emit_no_arg(Instruction::$op)
};
}
@@ -331,7 +331,7 @@ impl Compiler {
cache: impl FnOnce(&mut ir::CodeInfo) -> &mut IndexSet<String>,
) -> bytecode::NameIdx {
let name = self.mangle(name);
let cache = cache(self.current_codeinfo());
let cache = cache(self.current_code_info());
cache
.get_index_of(name.as_ref())
.unwrap_or_else(|| cache.insert_full(name.into_owned()).0)
@@ -821,7 +821,7 @@ impl Compiler {
Some(v) => {
if self.ctx.func == FunctionContext::AsyncFunction
&& self
.current_codeinfo()
.current_code_info()
.flags
.contains(bytecode::CodeFlags::IS_GENERATOR)
{
@@ -929,12 +929,12 @@ impl Compiler {
);
}
let mut funcflags = bytecode::MakeFunctionFlags::empty();
let mut func_flags = bytecode::MakeFunctionFlags::empty();
if have_defaults {
funcflags |= bytecode::MakeFunctionFlags::DEFAULTS;
func_flags |= bytecode::MakeFunctionFlags::DEFAULTS;
}
if !args.kw_defaults.is_empty() {
funcflags |= bytecode::MakeFunctionFlags::KW_ONLY_DEFAULTS;
func_flags |= bytecode::MakeFunctionFlags::KW_ONLY_DEFAULTS;
}
self.push_output(
@@ -954,15 +954,15 @@ impl Compiler {
}
if let Some(name) = args.vararg.as_deref() {
self.current_codeinfo().flags |= bytecode::CodeFlags::HAS_VARARGS;
self.current_code_info().flags |= bytecode::CodeFlags::HAS_VARARGS;
self.varname(&name.node.arg)?;
}
if let Some(name) = args.kwarg.as_deref() {
self.current_codeinfo().flags |= bytecode::CodeFlags::HAS_VARKEYWORDS;
self.current_code_info().flags |= bytecode::CodeFlags::HAS_VARKEYWORDS;
self.varname(&name.node.arg)?;
}
Ok(funcflags)
Ok(func_flags)
}
fn prepare_decorators(&mut self, decorator_list: &[ast::Expr]) -> CompileResult<()> {
@@ -1133,8 +1133,8 @@ impl Compiler {
// Create bytecode for this function:
self.prepare_decorators(decorator_list)?;
let mut funcflags = self.enter_function(name, args)?;
self.current_codeinfo()
let mut func_flags = self.enter_function(name, args)?;
self.current_code_info()
.flags
.set(bytecode::CodeFlags::IS_COROUTINE, is_async);
@@ -1157,7 +1157,7 @@ impl Compiler {
let (doc_str, body) = split_doc(body);
self.current_codeinfo()
self.current_code_info()
.constants
.insert_full(ConstantData::None);
@@ -1210,7 +1210,7 @@ impl Compiler {
}
if num_annotations > 0 {
funcflags |= bytecode::MakeFunctionFlags::ANNOTATIONS;
func_flags |= bytecode::MakeFunctionFlags::ANNOTATIONS;
emit!(
self,
Instruction::BuildMap {
@@ -1220,7 +1220,7 @@ impl Compiler {
}
if self.build_closure(&code) {
funcflags |= bytecode::MakeFunctionFlags::CLOSURE;
func_flags |= bytecode::MakeFunctionFlags::CLOSURE;
}
self.emit_constant(ConstantData::Code {
@@ -1231,7 +1231,7 @@ impl Compiler {
});
// Turn code object into function object:
emit!(self, Instruction::MakeFunction(funcflags));
emit!(self, Instruction::MakeFunction(func_flags));
emit!(self, Instruction::Duplicate);
self.load_docstring(doc_str);
@@ -1388,10 +1388,10 @@ impl Compiler {
self.qualified_path.append(global_path_prefix.as_mut());
self.ctx = prev_ctx;
let mut funcflags = bytecode::MakeFunctionFlags::empty();
let mut func_flags = bytecode::MakeFunctionFlags::empty();
if self.build_closure(&code) {
funcflags |= bytecode::MakeFunctionFlags::CLOSURE;
func_flags |= bytecode::MakeFunctionFlags::CLOSURE;
}
self.emit_constant(ConstantData::Code {
@@ -1402,7 +1402,7 @@ impl Compiler {
});
// Turn code object into function object:
emit!(self, Instruction::MakeFunction(funcflags));
emit!(self, Instruction::MakeFunction(func_flags));
self.emit_constant(ConstantData::Str {
value: name.to_owned(),
@@ -1417,7 +1417,7 @@ impl Compiler {
}
fn load_docstring(&mut self, doc_str: Option<String>) {
// TODO: __doc__ must be default None and no bytecodes unless it is Some
// TODO: __doc__ must be default None and no bytecode unless it is Some
// Duplicate top of stack (the function or class object)
// Doc string value:
@@ -1603,12 +1603,12 @@ impl Compiler {
&mut self,
left: &ast::Expr,
ops: &[ast::Cmpop],
vals: &[ast::Expr],
exprs: &[ast::Expr],
) -> CompileResult<()> {
assert!(!ops.is_empty());
assert_eq!(vals.len(), ops.len());
assert_eq!(exprs.len(), ops.len());
let (last_op, mid_ops) = ops.split_last().unwrap();
let (last_val, mid_vals) = vals.split_last().unwrap();
let (last_val, mid_exprs) = exprs.split_last().unwrap();
use bytecode::ComparisonOperator::*;
use bytecode::TestOperator::*;
@@ -1626,7 +1626,7 @@ impl Compiler {
};
// a == b == c == d
// compile into (pseudocode):
// compile into (pseudo code):
// result = a == b
// if result:
// result = b == c
@@ -1636,7 +1636,7 @@ impl Compiler {
// initialize lhs outside of loop
self.compile_expression(left)?;
let end_blocks = if mid_vals.is_empty() {
let end_blocks = if mid_exprs.is_empty() {
None
} else {
let break_block = self.new_block();
@@ -1645,7 +1645,7 @@ impl Compiler {
};
// for all comparisons except the last (as the last one doesn't need a conditional jump)
for (op, val) in mid_ops.iter().zip(mid_vals) {
for (op, val) in mid_ops.iter().zip(mid_exprs) {
self.compile_expression(val)?;
// store rhs for the next comparison in chain
emit!(self, Instruction::Duplicate);
@@ -2206,7 +2206,7 @@ impl Compiler {
let prev_ctx = self.ctx;
let name = "<lambda>".to_owned();
let mut funcflags = self.enter_function(&name, args)?;
let mut func_flags = self.enter_function(&name, args)?;
self.ctx = CompileContext {
loop_data: Option::None,
@@ -2214,7 +2214,7 @@ impl Compiler {
func: FunctionContext::Function,
};
self.current_codeinfo()
self.current_code_info()
.constants
.insert_full(ConstantData::None);
@@ -2222,14 +2222,14 @@ impl Compiler {
emit!(self, Instruction::ReturnValue);
let code = self.pop_code_object();
if self.build_closure(&code) {
funcflags |= bytecode::MakeFunctionFlags::CLOSURE;
func_flags |= bytecode::MakeFunctionFlags::CLOSURE;
}
self.emit_constant(ConstantData::Code {
code: Box::new(code),
});
self.emit_constant(ConstantData::Str { value: name });
// Turn code object into function object:
emit!(self, Instruction::MakeFunction(funcflags));
emit!(self, Instruction::MakeFunction(func_flags));
self.ctx = prev_ctx;
}
@@ -2345,24 +2345,24 @@ impl Compiler {
fn compile_keywords(&mut self, keywords: &[ast::Keyword]) -> CompileResult<()> {
let mut size = 0;
let groupby = keywords.iter().group_by(|e| e.node.arg.is_none());
for (is_unpacking, subkeywords) in &groupby {
for (is_unpacking, sub_keywords) in &groupby {
if is_unpacking {
for keyword in subkeywords {
for keyword in sub_keywords {
self.compile_expression(&keyword.node.value)?;
size += 1;
}
} else {
let mut subsize = 0;
for keyword in subkeywords {
let mut sub_size = 0;
for keyword in sub_keywords {
if let Some(name) = &keyword.node.arg {
self.emit_constant(ConstantData::Str {
value: name.to_owned(),
});
self.compile_expression(&keyword.node.value)?;
subsize += 1;
sub_size += 1;
}
}
emit!(self, Instruction::BuildMap { size: subsize });
emit!(self, Instruction::BuildMap { size: sub_size });
size += 1;
}
}
@@ -2634,9 +2634,9 @@ impl Compiler {
self.ctx = prev_ctx;
let mut funcflags = bytecode::MakeFunctionFlags::empty();
let mut func_flags = bytecode::MakeFunctionFlags::empty();
if self.build_closure(&code) {
funcflags |= bytecode::MakeFunctionFlags::CLOSURE;
func_flags |= bytecode::MakeFunctionFlags::CLOSURE;
}
// List comprehension code:
@@ -2650,7 +2650,7 @@ impl Compiler {
});
// Turn code object into function object:
emit!(self, Instruction::MakeFunction(funcflags));
emit!(self, Instruction::MakeFunction(func_flags));
// Evaluate iterated item:
self.compile_expression(&generators[0].iter)?;
@@ -2694,7 +2694,7 @@ impl Compiler {
});
}
fn emit_noarg(&mut self, ins: Instruction) {
fn emit_no_arg(&mut self, ins: Instruction) {
self._emit(ins, OpArg::null(), ir::BlockIdx::NULL)
}
@@ -2710,29 +2710,29 @@ impl Compiler {
// fn block_done()
fn emit_constant(&mut self, constant: ConstantData) {
let info = self.current_codeinfo();
let info = self.current_code_info();
let idx = info.constants.insert_full(constant).0.to_u32();
self.emit_arg(idx, |idx| Instruction::LoadConst { idx })
}
fn current_codeinfo(&mut self) -> &mut ir::CodeInfo {
fn current_code_info(&mut self) -> &mut ir::CodeInfo {
self.code_stack.last_mut().expect("no code on stack")
}
fn current_block(&mut self) -> &mut ir::Block {
let info = self.current_codeinfo();
let info = self.current_code_info();
&mut info.blocks[info.current_block]
}
fn new_block(&mut self) -> ir::BlockIdx {
let code = self.current_codeinfo();
let code = self.current_code_info();
let idx = ir::BlockIdx(code.blocks.len().to_u32());
code.blocks.push(ir::Block::default());
idx
}
fn switch_to_block(&mut self, block: ir::BlockIdx) {
let code = self.current_codeinfo();
let code = self.current_code_info();
let prev = code.current_block;
assert_eq!(
code.blocks[block].next,
@@ -2762,7 +2762,7 @@ impl Compiler {
}
fn mark_generator(&mut self) {
self.current_codeinfo().flags |= bytecode::CodeFlags::IS_GENERATOR
self.current_code_info().flags |= bytecode::CodeFlags::IS_GENERATOR
}
}
@@ -2882,7 +2882,7 @@ mod tests {
($value:expr) => {
insta::assert_snapshot!(
insta::internals::AutoName,
$value.display_expand_codeobjects().to_string(),
$value.display_expand_code_objects().to_string(),
stringify!($value)
)
};
@@ -2925,7 +2925,7 @@ if (True and False) or (False and True):
for stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')):
with self.subTest(type=type(stop_exc)):
try:
async with woohoo():
async with egg():
raise stop_exc
except Exception as ex:
self.assertIs(ex, stop_exc)

View File

@@ -45,6 +45,7 @@ pub struct InstructionInfo {
pub location: Location,
}
// spell-checker:ignore petgraph
// TODO: look into using petgraph for handling blocks and stuff? it's heavier than this, but it
// might enable more analysis/optimizations
#[derive(Debug)]
@@ -223,12 +224,12 @@ impl CodeInfo {
fn max_stackdepth(&self) -> u32 {
let mut maxdepth = 0u32;
let mut stack = Vec::with_capacity(self.blocks.len());
let mut startdepths = vec![u32::MAX; self.blocks.len()];
startdepths[0] = 0;
let mut start_depths = vec![u32::MAX; self.blocks.len()];
start_depths[0] = 0;
stack.push(BlockIdx(0));
const DEBUG: bool = false;
'process_blocks: while let Some(block) = stack.pop() {
let mut depth = startdepths[block.idx()];
let mut depth = start_depths[block.idx()];
if DEBUG {
eprintln!("===BLOCK {}===", block.0);
}
@@ -266,14 +267,14 @@ impl CodeInfo {
if target_depth > maxdepth {
maxdepth = target_depth
}
stackdepth_push(&mut stack, &mut startdepths, i.target, target_depth);
stackdepth_push(&mut stack, &mut start_depths, i.target, target_depth);
}
depth = new_depth;
if instr.unconditional_branch() {
continue 'process_blocks;
}
}
stackdepth_push(&mut stack, &mut startdepths, block.next, depth);
stackdepth_push(&mut stack, &mut start_depths, block.next, depth);
}
if DEBUG {
eprintln!("DONE: {maxdepth}");
@@ -293,7 +294,7 @@ impl InstrDisplayContext for CodeInfo {
fn get_varname(&self, i: usize) -> &str {
self.varname_cache[i].as_ref()
}
fn get_cellname(&self, i: usize) -> &str {
fn get_cell_name(&self, i: usize) -> &str {
self.cellvar_cache
.get_index(i)
.unwrap_or_else(|| &self.freevar_cache[i - self.cellvar_cache.len()])
@@ -303,11 +304,11 @@ impl InstrDisplayContext for CodeInfo {
fn stackdepth_push(
stack: &mut Vec<BlockIdx>,
startdepths: &mut [u32],
start_depths: &mut [u32],
target: BlockIdx,
depth: u32,
) {
let block_depth = &mut startdepths[target.idx()];
let block_depth = &mut start_depths[target.idx()];
if *block_depth == u32::MAX || depth > *block_depth {
*block_depth = depth;
stack.push(target);

View File

@@ -1,6 +1,6 @@
---
source: compiler/codegen/src/compile.rs
expression: "compile_exec(\"\\\nfor stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')):\n with self.subTest(type=type(stop_exc)):\n try:\n async with woohoo():\n raise stop_exc\n except Exception as ex:\n self.assertIs(ex, stop_exc)\n else:\n self.fail(f'{stop_exc} was suppressed')\n\")"
expression: "compile_exec(\"\\\nfor stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')):\n with self.subTest(type=type(stop_exc)):\n try:\n async with egg():\n raise stop_exc\n except Exception as ex:\n self.assertIs(ex, stop_exc)\n else:\n self.fail(f'{stop_exc} was suppressed')\n\")"
---
1 0 SetupLoop
1 LoadNameAny (0, StopIteration)
@@ -26,7 +26,7 @@ expression: "compile_exec(\"\\\nfor stop_exc in (StopIteration('spam'), StopAsyn
3 20 SetupExcept (40)
4 21 LoadNameAny (6, woohoo)
4 21 LoadNameAny (6, egg)
22 CallFunctionPositional(0)
23 BeforeAsyncWith
24 GetAwaitable

View File

@@ -16,7 +16,7 @@ use rustpython_ast as ast;
use rustpython_compiler_core::Location;
use std::{borrow::Cow, fmt};
/// Captures all symbols in the current scope, and has a list of subscopes in this scope.
/// Captures all symbols in the current scope, and has a list of sub-scopes in this scope.
#[derive(Clone)]
pub struct SymbolTable {
/// The name of this symbol table. Often the name of the class or function.
@@ -25,7 +25,7 @@ pub struct SymbolTable {
/// The type of symbol table
pub typ: SymbolTableType,
/// The line number in the sourcecode where this symboltable begins.
/// The line number in the source code where this symboltable begins.
pub line_number: usize,
// Return True if the block is a nested class or function
@@ -34,7 +34,7 @@ pub struct SymbolTable {
/// A set of symbols present on this scope level.
pub symbols: IndexMap<String, Symbol>,
/// A list of subscopes in the order as found in the
/// A list of sub-scopes in the order as found in the
/// AST nodes.
pub sub_tables: Vec<SymbolTable>,
}
@@ -107,7 +107,7 @@ bitflags! {
// this is required to correct the scope in the analysis.
const ASSIGNED_IN_COMPREHENSION = 0x040;
// indicates that the symbol is used a bound iterator variable. We distinguish this case
// from normal assignment to detect unallowed re-assignment to iterator variables.
// from normal assignment to detect disallowed re-assignment to iterator variables.
const ITER = 0x080;
/// indicates that the symbol is a free variable in a class method from the scope that the
/// class is defined in, e.g.:
@@ -531,7 +531,7 @@ enum SymbolUsage {
AnnotationAssigned,
Parameter,
AnnotationParameter,
AssignedNamedExprInCompr,
AssignedNamedExprInComprehension,
Iter,
}
@@ -741,7 +741,7 @@ impl SymbolTableBuilder {
Import { names } | ImportFrom { names, .. } => {
for name in names {
if let Some(alias) = &name.node.asname {
// `import mymodule as myalias`
// `import my_module as my_alias`
self.register_name(alias, SymbolUsage::Imported, location)?;
} else {
// `import module`
@@ -1042,7 +1042,11 @@ impl SymbolTableBuilder {
if let Name { id, .. } = &target.node {
let table = self.tables.last().unwrap();
if table.typ == SymbolTableType::Comprehension {
self.register_name(id, SymbolUsage::AssignedNamedExprInCompr, location)?;
self.register_name(
id,
SymbolUsage::AssignedNamedExprInComprehension,
location,
)?;
} else {
// omit one recursion. When the handling of an store changes for
// Identifiers this needs adapted - more forward safe would be
@@ -1256,7 +1260,7 @@ impl SymbolTableBuilder {
SymbolUsage::Assigned => {
flags.insert(SymbolFlags::ASSIGNED);
}
SymbolUsage::AssignedNamedExprInCompr => {
SymbolUsage::AssignedNamedExprInComprehension => {
flags.insert(SymbolFlags::ASSIGNED | SymbolFlags::ASSIGNED_IN_COMPREHENSION);
}
SymbolUsage::Global => {
@@ -1273,7 +1277,7 @@ impl SymbolTableBuilder {
// and even more checking
// it is not allowed to assign to iterator variables (by named expressions)
if flags.contains(SymbolFlags::ITER | SymbolFlags::ASSIGNED)
/*&& symbol.is_assign_namedexpr_in_comprehension*/
/*&& symbol.is_assign_named_expr_in_comprehension*/
{
return Err(SymbolTableError {
error:

View File

@@ -1,4 +1,4 @@
//! Implement python as a virtual machine with bytecodes. This module
//! Implement python as a virtual machine with bytecode. This module
//! implements bytecode structure.
use crate::{marshal, Location};
@@ -85,7 +85,7 @@ impl ConstantBag for BasicBag {
}
/// Primary container of a single code object. Each python function has
/// a codeobject. Also a module has a codeobject.
/// a code object. Also a module has a code object.
#[derive(Clone)]
pub struct CodeObject<C: Constant = ConstantData> {
pub instructions: Box<[CodeUnit]>,
@@ -147,7 +147,7 @@ impl fmt::Debug for OpArgByte {
}
}
/// a full 32-bit oparg, including any possible ExtendedArg extension
/// a full 32-bit op_arg, including any possible ExtendedArg extension
#[derive(Copy, Clone, Debug)]
#[repr(transparent)]
pub struct OpArg(pub u32);
@@ -156,7 +156,7 @@ impl OpArg {
OpArg(0)
}
/// Returns how many CodeUnits a instruction with this oparg will be encoded as
/// Returns how many CodeUnits a instruction with this op_arg will be encoded as
#[inline]
pub fn instr_size(self) -> usize {
(self.0 > 0xff) as usize + (self.0 > 0xff_ff) as usize + (self.0 > 0xff_ff_ff) as usize + 1
@@ -204,46 +204,46 @@ impl OpArgState {
}
pub trait OpArgType: Copy {
fn from_oparg(x: u32) -> Option<Self>;
fn to_oparg(self) -> u32;
fn from_op_arg(x: u32) -> Option<Self>;
fn to_op_arg(self) -> u32;
}
impl OpArgType for u32 {
#[inline(always)]
fn from_oparg(x: u32) -> Option<Self> {
fn from_op_arg(x: u32) -> Option<Self> {
Some(x)
}
#[inline(always)]
fn to_oparg(self) -> u32 {
fn to_op_arg(self) -> u32 {
self
}
}
impl OpArgType for bool {
#[inline(always)]
fn from_oparg(x: u32) -> Option<Self> {
fn from_op_arg(x: u32) -> Option<Self> {
Some(x != 0)
}
#[inline(always)]
fn to_oparg(self) -> u32 {
fn to_op_arg(self) -> u32 {
self as u32
}
}
macro_rules! oparg_enum {
($(#[$attr:meta])* $vis:vis enum $name:ident { $($(#[$var_attr:meta])* $var:ident = $discr:literal,)* }) => {
macro_rules! op_arg_enum {
($(#[$attr:meta])* $vis:vis enum $name:ident { $($(#[$var_attr:meta])* $var:ident = $value:literal,)* }) => {
$(#[$attr])*
$vis enum $name {
$($(#[$var_attr])* $var = $discr,)*
$($(#[$var_attr])* $var = $value,)*
}
impl OpArgType for $name {
fn to_oparg(self) -> u32 {
fn to_op_arg(self) -> u32 {
self as u32
}
fn from_oparg(x: u32) -> Option<Self> {
fn from_op_arg(x: u32) -> Option<Self> {
Some(match u8::try_from(x).ok()? {
$($discr => Self::$var,)*
$($value => Self::$var,)*
_ => return None,
})
}
@@ -261,7 +261,7 @@ impl<T: OpArgType> Arg<T> {
}
#[inline]
pub fn new(arg: T) -> (Self, OpArg) {
(Self(PhantomData), OpArg(arg.to_oparg()))
(Self(PhantomData), OpArg(arg.to_op_arg()))
}
#[inline]
pub fn new_single(arg: T) -> (Self, OpArgByte)
@@ -276,13 +276,13 @@ impl<T: OpArgType> Arg<T> {
}
#[inline(always)]
pub fn try_get(self, arg: OpArg) -> Option<T> {
T::from_oparg(arg.0)
T::from_op_arg(arg.0)
}
#[inline(always)]
/// # Safety
/// T::from_oparg(self) must succeed
/// T::from_op_arg(self) must succeed
pub unsafe fn get_unchecked(self, arg: OpArg) -> T {
match T::from_oparg(arg.0) {
match T::from_op_arg(arg.0) {
Some(t) => t,
None => std::hint::unreachable_unchecked(),
}
@@ -310,11 +310,11 @@ pub struct Label(pub u32);
impl OpArgType for Label {
#[inline(always)]
fn from_oparg(x: u32) -> Option<Self> {
fn from_op_arg(x: u32) -> Option<Self> {
Some(Label(x))
}
#[inline(always)]
fn to_oparg(self) -> u32 {
fn to_op_arg(self) -> u32 {
self.0
}
}
@@ -325,7 +325,7 @@ impl fmt::Display for Label {
}
}
oparg_enum!(
op_arg_enum!(
/// Transforms a value prior to formatting it.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u8)]
@@ -344,11 +344,11 @@ oparg_enum!(
impl TryFrom<usize> for ConversionFlag {
type Error = usize;
fn try_from(b: usize) -> Result<Self, Self::Error> {
u32::try_from(b).ok().and_then(Self::from_oparg).ok_or(b)
u32::try_from(b).ok().and_then(Self::from_op_arg).ok_or(b)
}
}
oparg_enum!(
op_arg_enum!(
/// The kind of Raise that occurred.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u8)]
@@ -634,11 +634,11 @@ bitflags! {
}
impl OpArgType for MakeFunctionFlags {
#[inline(always)]
fn from_oparg(x: u32) -> Option<Self> {
fn from_op_arg(x: u32) -> Option<Self> {
Some(unsafe { MakeFunctionFlags::from_bits_unchecked(x as u8) })
}
#[inline(always)]
fn to_oparg(self) -> u32 {
fn to_op_arg(self) -> u32 {
self.bits().into()
}
}
@@ -793,7 +793,7 @@ impl<C: Constant> BorrowedConstant<'_, C> {
}
}
oparg_enum!(
op_arg_enum!(
/// The possible comparison operators
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(u8)]
@@ -809,7 +809,7 @@ oparg_enum!(
}
);
oparg_enum!(
op_arg_enum!(
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(u8)]
pub enum TestOperator {
@@ -822,7 +822,7 @@ oparg_enum!(
}
);
oparg_enum!(
op_arg_enum!(
/// The possible Binary operators
/// # Examples
///
@@ -850,7 +850,7 @@ oparg_enum!(
}
);
oparg_enum!(
op_arg_enum!(
/// The possible unary operators
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(u8)]
@@ -870,12 +870,12 @@ pub struct UnpackExArgs {
impl OpArgType for UnpackExArgs {
#[inline(always)]
fn from_oparg(x: u32) -> Option<Self> {
fn from_op_arg(x: u32) -> Option<Self> {
let [before, after, ..] = x.to_le_bytes();
Some(Self { before, after })
}
#[inline(always)]
fn to_oparg(self) -> u32 {
fn to_op_arg(self) -> u32 {
u32::from_le_bytes([self.before, self.after, 0, 0])
}
}
@@ -925,20 +925,20 @@ impl<C: Constant> CodeObject<C> {
pub fn arg_names(&self) -> Arguments<C::Name> {
let nargs = self.arg_count as usize;
let nkwargs = self.kwonlyarg_count as usize;
let mut varargspos = nargs + nkwargs;
let mut varargs_pos = nargs + nkwargs;
let posonlyargs = &self.varnames[..self.posonlyarg_count as usize];
let args = &self.varnames[..nargs];
let kwonlyargs = &self.varnames[nargs..varargspos];
let kwonlyargs = &self.varnames[nargs..varargs_pos];
let vararg = if self.flags.contains(CodeFlags::HAS_VARARGS) {
let vararg = &self.varnames[varargspos];
varargspos += 1;
let vararg = &self.varnames[varargs_pos];
varargs_pos += 1;
Some(vararg)
} else {
None
};
let varkwarg = if self.flags.contains(CodeFlags::HAS_VARKEYWORDS) {
Some(&self.varnames[varargspos])
Some(&self.varnames[varargs_pos])
} else {
None
};
@@ -968,7 +968,7 @@ impl<C: Constant> CodeObject<C> {
fn display_inner(
&self,
f: &mut fmt::Formatter,
expand_codeobjects: bool,
expand_code_objects: bool,
level: usize,
) -> fmt::Result {
let label_targets = self.label_targets();
@@ -1007,14 +1007,14 @@ impl<C: Constant> CodeObject<C> {
write!(f, "{arrow} {offset:offset_digits$} ")?;
// instruction
instruction.fmt_dis(arg, f, self, expand_codeobjects, 21, level)?;
instruction.fmt_dis(arg, f, self, expand_code_objects, 21, level)?;
writeln!(f)?;
}
Ok(())
}
/// Recursively display this CodeObject
pub fn display_expand_codeobjects(&self) -> impl fmt::Display + '_ {
pub fn display_expand_code_objects(&self) -> impl fmt::Display + '_ {
struct Display<'a, C: Constant>(&'a CodeObject<C>);
impl<C: Constant> fmt::Display for Display<'_, C> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -1287,7 +1287,7 @@ impl Instruction {
arg: OpArg,
f: &mut fmt::Formatter,
ctx: &impl InstrDisplayContext,
expand_codeobjects: bool,
expand_code_objects: bool,
pad: usize,
level: usize,
) -> fmt::Result {
@@ -1295,26 +1295,26 @@ impl Instruction {
($variant:ident) => {
write!(f, stringify!($variant))
};
($variant:ident, $map:ident = $argmarker:expr) => {{
let arg = $argmarker.get(arg);
($variant:ident, $map:ident = $arg_marker:expr) => {{
let arg = $arg_marker.get(arg);
write!(f, "{:pad$}({}, {})", stringify!($variant), arg, $map(arg))
}};
($variant:ident, $argmarker:expr) => {
write!(f, "{:pad$}({})", stringify!($variant), $argmarker.get(arg))
($variant:ident, $arg_marker:expr) => {
write!(f, "{:pad$}({})", stringify!($variant), $arg_marker.get(arg))
};
($variant:ident, ?$argmarker:expr) => {
($variant:ident, ?$arg_marker:expr) => {
write!(
f,
"{:pad$}({:?})",
stringify!($variant),
$argmarker.get(arg)
$arg_marker.get(arg)
)
};
}
let varname = |i: u32| ctx.get_varname(i as usize);
let name = |i: u32| ctx.get_name(i as usize);
let cellname = |i: u32| ctx.get_cellname(i as usize);
let cell_name = |i: u32| ctx.get_cell_name(i as usize);
match self {
ImportName { idx } => w!(ImportName, name = idx),
@@ -1324,17 +1324,17 @@ impl Instruction {
LoadFast(idx) => w!(LoadFast, varname = idx),
LoadNameAny(idx) => w!(LoadNameAny, name = idx),
LoadGlobal(idx) => w!(LoadGlobal, name = idx),
LoadDeref(idx) => w!(LoadDeref, cellname = idx),
LoadClassDeref(idx) => w!(LoadClassDeref, cellname = idx),
LoadDeref(idx) => w!(LoadDeref, cell_name = idx),
LoadClassDeref(idx) => w!(LoadClassDeref, cell_name = idx),
StoreFast(idx) => w!(StoreFast, varname = idx),
StoreLocal(idx) => w!(StoreLocal, name = idx),
StoreGlobal(idx) => w!(StoreGlobal, name = idx),
StoreDeref(idx) => w!(StoreDeref, cellname = idx),
StoreDeref(idx) => w!(StoreDeref, cell_name = idx),
DeleteFast(idx) => w!(DeleteFast, varname = idx),
DeleteLocal(idx) => w!(DeleteLocal, name = idx),
DeleteGlobal(idx) => w!(DeleteGlobal, name = idx),
DeleteDeref(idx) => w!(DeleteDeref, cellname = idx),
LoadClosure(i) => w!(LoadClosure, cellname = i),
DeleteDeref(idx) => w!(DeleteDeref, cell_name = idx),
LoadClosure(i) => w!(LoadClosure, cell_name = i),
Subscript => w!(Subscript),
StoreSubscript => w!(StoreSubscript),
DeleteSubscript => w!(DeleteSubscript),
@@ -1343,7 +1343,7 @@ impl Instruction {
LoadConst { idx } => {
let value = ctx.get_constant(idx.get(arg) as usize);
match value.borrow_constant() {
BorrowedConstant::Code { code } if expand_codeobjects => {
BorrowedConstant::Code { code } if expand_code_objects => {
write!(f, "{:pad$}({:?}):", "LoadConst", code)?;
code.display_inner(f, true, level + 1)?;
Ok(())
@@ -1434,7 +1434,7 @@ pub trait InstrDisplayContext {
fn get_constant(&self, i: usize) -> &Self::Constant;
fn get_name(&self, i: usize) -> &str;
fn get_varname(&self, i: usize) -> &str;
fn get_cellname(&self, i: usize) -> &str;
fn get_cell_name(&self, i: usize) -> &str;
}
impl<C: Constant> InstrDisplayContext for CodeObject<C> {
@@ -1448,7 +1448,7 @@ impl<C: Constant> InstrDisplayContext for CodeObject<C> {
fn get_varname(&self, i: usize) -> &str {
self.varnames[i].as_ref()
}
fn get_cellname(&self, i: usize) -> &str {
fn get_cell_name(&self, i: usize) -> &str {
self.cellvars
.get(i)
.unwrap_or_else(|| &self.freevars[i - self.cellvars.len()])
@@ -1491,7 +1491,7 @@ pub mod frozen_lib {
}
impl<B: AsRef<[u8]>> FrozenCodeObject<B> {
/// Decode a frozen codeobject
/// Decode a frozen code object
#[inline]
pub fn decode<Bag: AsBag>(
&self,

View File

@@ -1,7 +1,7 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/// Sourcecode location.
/// Source code location.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Location {

View File

@@ -112,7 +112,7 @@ fn gen_phf(out_dir: &Path) {
.entry("False", "Tok::False")
.entry("None", "Tok::None")
.entry("True", "Tok::True")
// moreso "standard" keywords
// more so "standard" keywords
.entry("and", "Tok::And")
.entry("as", "Tok::As")
.entry("assert", "Tok::Assert")

View File

@@ -241,6 +241,7 @@ where
lxr.window.slide();
lxr.window.slide();
// TODO: Handle possible mismatch between BOM and explicit encoding declaration.
// spell-checker:ignore feff
if let Some('\u{feff}') = lxr.window[0] {
lxr.window.slide();
}
@@ -1085,7 +1086,7 @@ where
}
}
' ' | '\t' | '\x0C' => {
// Skip whitespaces
// Skip white-spaces
self.next_char();
while let Some(' ' | '\t' | '\x0C') = self.window[0] {
self.next_char();
@@ -1327,7 +1328,7 @@ mod tests {
lexer.map(|x| x.unwrap().1).collect()
}
fn stok(s: &str) -> Tok {
fn str_tok(s: &str) -> Tok {
Tok::String {
value: s.to_owned(),
kind: StringKind::String,
@@ -1335,7 +1336,7 @@ mod tests {
}
}
fn raw_stok(s: &str) -> Tok {
fn raw_str_tok(s: &str) -> Tok {
Tok::String {
value: s.to_owned(),
kind: StringKind::RawString,
@@ -1434,13 +1435,13 @@ mod tests {
#[test]
fn test_assignment() {
let source = r"avariable = 99 + 2-0";
let source = r"a_variable = 99 + 2-0";
let tokens = lex_source(source);
assert_eq!(
tokens,
vec![
Tok::Name {
name: String::from("avariable"),
name: String::from("a_variable"),
},
Tok::Equal,
Tok::Int {
@@ -1663,13 +1664,13 @@ mod tests {
vec![
Tok::Lpar,
Tok::NonLogicalNewline,
stok("a"),
str_tok("a"),
Tok::NonLogicalNewline,
stok("b"),
str_tok("b"),
Tok::NonLogicalNewline,
Tok::NonLogicalNewline,
stok("c"),
stok("d"),
str_tok("c"),
str_tok("d"),
Tok::NonLogicalNewline,
Tok::Rpar,
Tok::Newline,
@@ -1716,15 +1717,15 @@ mod tests {
assert_eq!(
tokens,
vec![
stok("double"),
stok("single"),
stok(r"can\'t"),
stok(r#"\\\""#),
stok(r"\t\r\n"),
stok(r"\g"),
raw_stok(r"raw\'"),
stok(r"\420"),
stok(r"\200\0a"),
str_tok("double"),
str_tok("single"),
str_tok(r"can\'t"),
str_tok(r#"\\\""#),
str_tok(r"\t\r\n"),
str_tok(r"\g"),
raw_str_tok(r"raw\'"),
str_tok(r"\420"),
str_tok(r"\200\0a"),
Tok::Newline,
]
);
@@ -1740,7 +1741,7 @@ mod tests {
assert_eq!(
tokens,
vec![
stok("abc\\\ndef"),
str_tok("abc\\\ndef"),
Tok::Newline,
]
)
@@ -1759,7 +1760,7 @@ mod tests {
fn test_escape_unicode_name() {
let source = r#""\N{EN SPACE}""#;
let tokens = lex_source(source);
assert_eq!(tokens, vec![stok(r"\N{EN SPACE}"), Tok::Newline])
assert_eq!(tokens, vec![str_tok(r"\N{EN SPACE}"), Tok::Newline])
}
macro_rules! test_triple_quoted {

View File

@@ -433,14 +433,14 @@ class Foo(A, B):
}
#[test]
fn test_parse_boolop_or() {
fn test_parse_bool_op_or() {
let source = "x or y";
let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
#[test]
fn test_parse_boolop_and() {
fn test_parse_bool_op_and() {
let source = "x and y";
let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast);
@@ -513,10 +513,10 @@ with (0 as a, 1 as b,): pass
#[test]
fn test_star_index() {
let source = "\
array_slice = array[0, *idxs, -1]
array[0, *idxs, -1] = array_slice
array[*idxs_to_select, *idxs_to_select]
array[3:5, *idxs_to_select]
array_slice = array[0, *indexes, -1]
array[0, *indexes, -1] = array_slice
array[*indexes_to_select, *indexes_to_select]
array[3:5, *indexes_to_select]
";
let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast);

View File

@@ -1,42 +0,0 @@
---
source: compiler/parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 1,
},
custom: (),
node: Assign {
targets: [
Located {
location: Location {
row: 1,
column: 1,
},
custom: (),
node: Name {
id: "x",
ctx: Store,
},
},
],
value: Located {
location: Location {
row: 1,
column: 5,
},
custom: (),
node: Constant {
value: Int(
1,
),
kind: None,
},
},
type_comment: None,
},
},
]

View File

@@ -1,6 +1,5 @@
---
source: compiler/parser/src/function.rs
assertion_line: 165
expression: parse_ast
---
Ok(

View File

@@ -1,6 +1,5 @@
---
source: compiler/parser/src/function.rs
assertion_line: 165
expression: parse_ast
---
Ok(

View File

@@ -1,5 +1,5 @@
---
source: parser/src/parser.rs
source: compiler/parser/src/parser.rs
expression: parse_ast
---
[]

View File

@@ -11,7 +11,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 1,
column: 33,
column: 36,
},
),
custom: (),
@@ -43,7 +43,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 1,
column: 33,
column: 36,
},
),
custom: (),
@@ -73,7 +73,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 1,
column: 32,
column: 35,
},
),
custom: (),
@@ -106,7 +106,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 1,
column: 28,
column: 31,
},
),
custom: (),
@@ -119,12 +119,12 @@ expression: parse_ast
end_location: Some(
Location {
row: 1,
column: 28,
column: 31,
},
),
custom: (),
node: Name {
id: "idxs",
id: "indexes",
ctx: Load,
},
},
@@ -134,12 +134,12 @@ expression: parse_ast
Located {
location: Location {
row: 1,
column: 30,
column: 33,
},
end_location: Some(
Location {
row: 1,
column: 32,
column: 35,
},
),
custom: (),
@@ -148,12 +148,12 @@ expression: parse_ast
operand: Located {
location: Location {
row: 1,
column: 31,
column: 34,
},
end_location: Some(
Location {
row: 1,
column: 32,
column: 35,
},
),
custom: (),
@@ -184,7 +184,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 2,
column: 33,
column: 36,
},
),
custom: (),
@@ -198,7 +198,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 2,
column: 19,
column: 22,
},
),
custom: (),
@@ -228,7 +228,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 2,
column: 18,
column: 21,
},
),
custom: (),
@@ -261,7 +261,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 2,
column: 14,
column: 17,
},
),
custom: (),
@@ -274,12 +274,12 @@ expression: parse_ast
end_location: Some(
Location {
row: 2,
column: 14,
column: 17,
},
),
custom: (),
node: Name {
id: "idxs",
id: "indexes",
ctx: Load,
},
},
@@ -289,12 +289,12 @@ expression: parse_ast
Located {
location: Location {
row: 2,
column: 16,
column: 19,
},
end_location: Some(
Location {
row: 2,
column: 18,
column: 21,
},
),
custom: (),
@@ -303,12 +303,12 @@ expression: parse_ast
operand: Located {
location: Location {
row: 2,
column: 17,
column: 20,
},
end_location: Some(
Location {
row: 2,
column: 18,
column: 21,
},
),
custom: (),
@@ -332,12 +332,12 @@ expression: parse_ast
value: Located {
location: Location {
row: 2,
column: 22,
column: 25,
},
end_location: Some(
Location {
row: 2,
column: 33,
column: 36,
},
),
custom: (),
@@ -357,7 +357,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 3,
column: 39,
column: 45,
},
),
custom: (),
@@ -370,7 +370,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 3,
column: 39,
column: 45,
},
),
custom: (),
@@ -400,7 +400,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 3,
column: 38,
column: 44,
},
),
custom: (),
@@ -414,7 +414,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 3,
column: 21,
column: 24,
},
),
custom: (),
@@ -427,12 +427,12 @@ expression: parse_ast
end_location: Some(
Location {
row: 3,
column: 21,
column: 24,
},
),
custom: (),
node: Name {
id: "idxs_to_select",
id: "indexes_to_select",
ctx: Load,
},
},
@@ -442,12 +442,12 @@ expression: parse_ast
Located {
location: Location {
row: 3,
column: 23,
column: 26,
},
end_location: Some(
Location {
row: 3,
column: 38,
column: 44,
},
),
custom: (),
@@ -455,17 +455,17 @@ expression: parse_ast
value: Located {
location: Location {
row: 3,
column: 24,
column: 27,
},
end_location: Some(
Location {
row: 3,
column: 38,
column: 44,
},
),
custom: (),
node: Name {
id: "idxs_to_select",
id: "indexes_to_select",
ctx: Load,
},
},
@@ -489,7 +489,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 4,
column: 27,
column: 30,
},
),
custom: (),
@@ -502,7 +502,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 4,
column: 27,
column: 30,
},
),
custom: (),
@@ -532,7 +532,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 4,
column: 26,
column: 29,
},
),
custom: (),
@@ -604,7 +604,7 @@ expression: parse_ast
end_location: Some(
Location {
row: 4,
column: 26,
column: 29,
},
),
custom: (),
@@ -617,12 +617,12 @@ expression: parse_ast
end_location: Some(
Location {
row: 4,
column: 26,
column: 29,
},
),
custom: (),
node: Name {
id: "idxs_to_select",
id: "indexes_to_select",
ctx: Load,
},
},

View File

@@ -1,6 +1,5 @@
---
source: compiler/parser/src/string.rs
assertion_line: 690
expression: "parse_fstring(\"\").unwrap()"
---
[]

View File

@@ -1,6 +1,5 @@
---
source: compiler/parser/src/string.rs
assertion_line: 669
expression: parse_ast
---
[

View File

@@ -1,6 +1,5 @@
---
source: compiler/parser/src/string.rs
assertion_line: 766
expression: parse_ast
---
[

View File

@@ -1,6 +1,5 @@
---
source: compiler/parser/src/string.rs
assertion_line: 677
expression: parse_ast
---
[

View File

@@ -1,6 +1,5 @@
---
source: compiler/parser/src/string.rs
assertion_line: 759
expression: parse_ast
---
[

View File

@@ -1,6 +1,5 @@
---
source: compiler/parser/src/string.rs
assertion_line: 685
expression: parse_ast
---
[

View File

@@ -1,6 +1,5 @@
---
source: compiler/parser/src/string.rs
assertion_line: 787
expression: parse_ast
---
[

View File

@@ -27,7 +27,7 @@ where
{
pub fn new(lexer: I, mode: Mode) -> Self {
Self {
underlying: lexer.multipeek(),
underlying: lexer.multipeek(), // spell-checker:ignore multipeek
start_of_line: matches!(mode, Mode::Interactive | Mode::Module),
}
}

View File

@@ -179,7 +179,7 @@ impl<'a> StringParser<'a> {
let mut expression = String::new();
let mut spec = None;
let mut delims = Vec::new();
let mut delimiters = Vec::new();
let mut conversion = ConversionFlag::None;
let mut self_documenting = false;
let mut trailing_seq = String::new();
@@ -194,7 +194,7 @@ impl<'a> StringParser<'a> {
expression.push('=');
self.next_char();
}
'!' if delims.is_empty() && self.peek() != Some(&'=') => {
'!' if delimiters.is_empty() && self.peek() != Some(&'=') => {
if expression.trim().is_empty() {
return Err(FStringError::new(EmptyExpression, self.get_pos()).into());
}
@@ -223,11 +223,11 @@ impl<'a> StringParser<'a> {
// match a python 3.8 self documenting expression
// format '{' PYTHON_EXPRESSION '=' FORMAT_SPECIFIER? '}'
'=' if self.peek() != Some(&'=') && delims.is_empty() => {
'=' if self.peek() != Some(&'=') && delimiters.is_empty() => {
self_documenting = true;
}
':' if delims.is_empty() => {
':' if delimiters.is_empty() => {
let parsed_spec = self.parse_spec(nested)?;
spec = Some(Box::new(self.expr(ExprKind::JoinedStr {
@@ -236,10 +236,10 @@ impl<'a> StringParser<'a> {
}
'(' | '{' | '[' => {
expression.push(ch);
delims.push(ch);
delimiters.push(ch);
}
')' => {
let last_delim = delims.pop();
let last_delim = delimiters.pop();
match last_delim {
Some('(') => {
expression.push(ch);
@@ -257,7 +257,7 @@ impl<'a> StringParser<'a> {
}
}
']' => {
let last_delim = delims.pop();
let last_delim = delimiters.pop();
match last_delim {
Some('[') => {
expression.push(ch);
@@ -274,8 +274,8 @@ impl<'a> StringParser<'a> {
}
}
}
'}' if !delims.is_empty() => {
let last_delim = delims.pop();
'}' if !delimiters.is_empty() => {
let last_delim = delimiters.pop();
match last_delim {
Some('{') => {
expression.push(ch);
@@ -800,7 +800,7 @@ mod tests {
}
#[test]
fn test_fstring_parse_selfdocumenting_base() {
fn test_fstring_parse_self_documenting_base() {
let src = "{user=}";
let parse_ast = parse_fstring(src).unwrap();
@@ -808,7 +808,7 @@ mod tests {
}
#[test]
fn test_fstring_parse_selfdocumenting_base_more() {
fn test_fstring_parse_self_documenting_base_more() {
let src = "mix {user=} with text and {second=}";
let parse_ast = parse_fstring(src).unwrap();
@@ -816,7 +816,7 @@ mod tests {
}
#[test]
fn test_fstring_parse_selfdocumenting_format() {
fn test_fstring_parse_self_documenting_format() {
let src = "{user=:>10}";
let parse_ast = parse_fstring(src).unwrap();
@@ -877,14 +877,14 @@ mod tests {
}
#[test]
fn test_parse_fstring_selfdoc_prec_space() {
fn test_parse_fstring_self_doc_prec_space() {
let source = "{x =}";
let parse_ast = parse_fstring(source).unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
#[test]
fn test_parse_fstring_selfdoc_trailing_space() {
fn test_parse_fstring_self_doc_trailing_space() {
let source = "{x= }";
let parse_ast = parse_fstring(source).unwrap();
insta::assert_debug_snapshot!(parse_ast);
@@ -979,7 +979,7 @@ mod tests {
#[test]
fn test_escape_char_in_byte_literal() {
// backslash does not escape
let source = r##"b"omkmok\Xaa""##;
let source = r##"b"omkmok\Xaa""##; // spell-checker:ignore omkmok
let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast);
}

View File

@@ -50,7 +50,7 @@ fn error_from_parse(error: parser::ParseError, source: &str) -> CompileError {
CompileError::from(error, source)
}
/// Compile a given sourcecode into a bytecode object.
/// Compile a given source code into a bytecode object.
pub fn compile(
source: &str,
mode: compile::Mode,

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),

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!(),

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)]",
)
})
}

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)?;

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())
}

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,13 +82,13 @@ 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 {
println!("{}", code.display_expand_codeobjects());
if expand_code_objects {
println!("{}", code.display_expand_code_objects());
} else {
println!("{code}");
}

View File

@@ -113,7 +113,7 @@ assert f'{"42"=!s:<5}' == '"42"=42 ', '#'+ f'{"42"=!s:<5}' +'#'
assert f'{"42"=!s:>5}' == '"42"= 42', '#'+ f'{"42"=!s:>5}' +'#'
### Tests for fstring selfdocumenting form CPython
### Tests for fstring self documenting form CPython
class C:
def assertEqual(self, a,b):

View File

@@ -1,3 +1,13 @@
// spell-checker:ignore libsqlite3 threadsafety PYSQLITE decltypes colnames collseq cantinit dirtywal
// spell-checker:ignore corruptfs narg setinputsizes setoutputsize lastrowid arraysize executemany
// spell-checker:ignore blobopen executescript iterdump getlimit setlimit errorcode errorname
// spell-checker:ignore rowid rowcount fetchone fetchmany fetchall errcode errname vtable pagecount
// spell-checker:ignore autocommit libversion toobig errmsg nomem threadsafe longlong vdbe reindex
// spell-checker:ignore savepoint cantopen ioerr nolfs nomem notadb notfound fullpath notempdir vtab
// spell-checker:ignore checkreservedlock noent fstat rdlock shmlock shmmap shmopen shmsize sharedcache
// spell-checker:ignore cantlock commithook foreignkey notnull primarykey gettemppath autoindex convpath
// spell-checker:ignore dbmoved vnode nbytes
use rustpython_vm::{PyObjectRef, VirtualMachine};
// pub(crate) use _sqlite::make_module;
@@ -365,7 +375,7 @@ mod _sqlite {
})
}
fn retrive(&self) -> (&PyObject, &VirtualMachine) {
fn retrieve(&self) -> (&PyObject, &VirtualMachine) {
unsafe { (&*self.obj, &*self.vm) }
}
@@ -379,7 +389,7 @@ mod _sqlite {
argv: *mut *mut sqlite3_value,
) {
let context = SqliteContext::from(context);
let (func, vm) = (*context.user_data::<Self>()).retrive();
let (func, vm) = (*context.user_data::<Self>()).retrieve();
let args = std::slice::from_raw_parts(argv, argc as usize);
let f = || -> PyResult<()> {
@@ -406,7 +416,7 @@ mod _sqlite {
argv: *mut *mut sqlite3_value,
) {
let context = SqliteContext::from(context);
let (cls, vm) = (*context.user_data::<Self>()).retrive();
let (cls, vm) = (*context.user_data::<Self>()).retrieve();
let args = std::slice::from_raw_parts(argv, argc as usize);
let instance = context.aggregate_context::<*const PyObject>();
if (*instance).is_null() {
@@ -428,7 +438,7 @@ mod _sqlite {
unsafe extern "C" fn finalize_callback(context: *mut sqlite3_context) {
let context = SqliteContext::from(context);
let (_, vm) = (*context.user_data::<Self>()).retrive();
let (_, vm) = (*context.user_data::<Self>()).retrieve();
let instance = context.aggregate_context::<*const PyObject>();
let Some(instance) = (*instance).as_ref() else { return; };
@@ -442,7 +452,7 @@ mod _sqlite {
b_len: c_int,
b_ptr: *const c_void,
) -> c_int {
let (callable, vm) = (*data.cast::<Self>()).retrive();
let (callable, vm) = (*data.cast::<Self>()).retrieve();
let f = || -> PyResult<c_int> {
let text1 = ptr_to_string(a_ptr.cast(), a_len, null_mut(), vm)?;
@@ -469,7 +479,7 @@ mod _sqlite {
unsafe extern "C" fn value_callback(context: *mut sqlite3_context) {
let context = SqliteContext::from(context);
let (_, vm) = (*context.user_data::<Self>()).retrive();
let (_, vm) = (*context.user_data::<Self>()).retrieve();
let instance = context.aggregate_context::<*const PyObject>();
let instance = &**instance;
@@ -482,7 +492,7 @@ mod _sqlite {
argv: *mut *mut sqlite3_value,
) {
let context = SqliteContext::from(context);
let (_, vm) = (*context.user_data::<Self>()).retrive();
let (_, vm) = (*context.user_data::<Self>()).retrieve();
let args = std::slice::from_raw_parts(argv, argc as usize);
let instance = context.aggregate_context::<*const PyObject>();
let instance = &**instance;
@@ -498,7 +508,7 @@ mod _sqlite {
db_name: *const libc::c_char,
access: *const libc::c_char,
) -> c_int {
let (callable, vm) = (*data.cast::<Self>()).retrive();
let (callable, vm) = (*data.cast::<Self>()).retrieve();
let f = || -> PyResult<c_int> {
let arg1 = ptr_to_str(arg1, vm)?;
let arg2 = ptr_to_str(arg2, vm)?;
@@ -521,7 +531,7 @@ mod _sqlite {
stmt: *mut c_void,
sql: *mut c_void,
) -> c_int {
let (callable, vm) = (*data.cast::<Self>()).retrive();
let (callable, vm) = (*data.cast::<Self>()).retrieve();
let expanded = sqlite3_expanded_sql(stmt.cast());
let f = || -> PyResult<()> {
let stmt = ptr_to_str(expanded, vm).or_else(|_| ptr_to_str(sql.cast(), vm))?;
@@ -533,7 +543,7 @@ mod _sqlite {
}
unsafe extern "C" fn progress_callback(data: *mut c_void) -> c_int {
let (callable, vm) = (*data.cast::<Self>()).retrive();
let (callable, vm) = (*data.cast::<Self>()).retrieve();
if let Ok(val) = callable.call((), vm) {
if let Ok(val) = val.is_true(vm) {
return val as c_int;
@@ -922,7 +932,7 @@ mod _sqlite {
#[pymethod]
fn commit(&self, vm: &VirtualMachine) -> PyResult<()> {
self.db_lock(vm)?.implicity_commit(vm)
self.db_lock(vm)?.implicit_commit(vm)
}
#[pymethod]
@@ -1115,7 +1125,7 @@ mod _sqlite {
// TODO: replace with Result.inspect_err when stable
if let Err(exc) = db.check(ret, vm) {
// create_colation do not call destructor if error occur
// create_collation do not call destructor if error occur
unsafe { Box::from_raw(data) };
Err(exc)
} else {
@@ -1526,7 +1536,7 @@ mod _sqlite {
db.sql_limit(script.byte_len(), vm)?;
db.implicity_commit(vm)?;
db.implicit_commit(vm)?;
let script = script.to_cstring(vm)?;
let mut ptr = script.as_ptr();
@@ -2124,8 +2134,9 @@ mod _sqlite {
let ret = inner.blob.write_single(value, index);
self.check(ret, vm)
} else if let Some(_slice) = needle.payload::<PySlice>() {
Err(vm
.new_not_implemented_error("Blob slice assigment is not implmented".to_owned()))
Err(vm.new_not_implemented_error(
"Blob slice assignment is not implemented".to_owned(),
))
// let blob_len = inner.blob.bytes();
// let slice = slice.to_saturated(vm)?;
// let (range, step, length) = slice.adjust_indices(blob_len as usize);
@@ -2380,7 +2391,7 @@ mod _sqlite {
unsafe { sqlite3_last_insert_rowid(self.db) }
}
fn implicity_commit(self, vm: &VirtualMachine) -> PyResult<()> {
fn implicit_commit(self, vm: &VirtualMachine) -> PyResult<()> {
if self.is_autocommit() {
Ok(())
} else {

View File

@@ -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 {}

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)]

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;

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},

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>],
)

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);

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>(