Skip to content

Commit 3a6442f

Browse files
authored
Merge pull request RustPython#2006 from Lynskylate/try-to-use-local
Use loadname local replace loadname free
2 parents 357f211 + 2f26737 commit 3a6442f

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Lib/_codecs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,11 +1485,11 @@ def PyUnicode_DecodeUnicodeEscape(s, size, errors):
14851485
message = "unknown Unicode character name"
14861486
st = s[pos+1:look]
14871487
try:
1488-
chr = unicodedata.lookup("%s" % st)
1488+
chr_codec = unicodedata.lookup("%s" % st)
14891489
except LookupError as e:
14901490
x = unicode_call_errorhandler(errors, "unicodeescape", message, s, pos-1, look+1)
14911491
else:
1492-
x = chr, look + 1
1492+
x = chr_codec, look + 1
14931493
p += x[0]
14941494
pos = x[1]
14951495
else:

compiler/src/compile.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,15 @@ impl<O: OutputStream> Compiler<O> {
298298
SymbolScope::Global => bytecode::NameScope::Global,
299299
SymbolScope::Nonlocal => bytecode::NameScope::NonLocal,
300300
SymbolScope::Unknown => bytecode::NameScope::Free,
301-
SymbolScope::Local => bytecode::NameScope::Free,
301+
SymbolScope::Local => {
302+
// Only in function block, we use load local
303+
// https://github.com/python/cpython/blob/master/Python/compile.c#L3582
304+
if self.ctx.in_func() {
305+
bytecode::NameScope::Local
306+
} else {
307+
bytecode::NameScope::Free
308+
}
309+
}
302310
}
303311
}
304312

compiler/src/symboltable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,11 @@ impl SymbolTableBuilder {
698698
self.scan_expressions(vals, context)?;
699699
}
700700
Subscript { a, b } => {
701-
self.scan_expression(a, context)?;
702-
self.scan_expression(b, context)?;
701+
self.scan_expression(a, &ExpressionContext::Load)?;
702+
self.scan_expression(b, &ExpressionContext::Load)?;
703703
}
704704
Attribute { value, .. } => {
705-
self.scan_expression(value, context)?;
705+
self.scan_expression(value, &ExpressionContext::Load)?;
706706
}
707707
Dict { elements } => {
708708
for (key, value) in elements {

0 commit comments

Comments
 (0)