mirror of
https://github.com/python/cpython.git
synced 2025-09-17 22:20:23 +00:00
Fix arigo's funky LOAD_NAME bug: implicit globals inside classes have
historically been looked up using LOAD_NAME, not LOAD_GLOBAL. looked up by LOAD_NAME, not
This commit is contained in:
parent
ac699efad8
commit
d403c45386
2 changed files with 11 additions and 1 deletions
|
@ -440,6 +440,15 @@ vereq(test(6)(2), 8)
|
||||||
x = -1
|
x = -1
|
||||||
vereq(test(3)(2), 5)
|
vereq(test(3)(2), 5)
|
||||||
|
|
||||||
|
looked_up_by_load_name = False
|
||||||
|
class X:
|
||||||
|
# Implicit globals inside classes are be looked up by LOAD_NAME, not
|
||||||
|
# LOAD_GLOBAL.
|
||||||
|
locals()['looked_up_by_load_name'] = True
|
||||||
|
passed = looked_up_by_load_name
|
||||||
|
|
||||||
|
verify(X.passed)
|
||||||
|
|
||||||
print "18. verify that locals() works"
|
print "18. verify that locals() works"
|
||||||
|
|
||||||
def f(x):
|
def f(x):
|
||||||
|
|
|
@ -2731,7 +2731,8 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
|
||||||
optype = OP_FAST;
|
optype = OP_FAST;
|
||||||
break;
|
break;
|
||||||
case GLOBAL_IMPLICIT:
|
case GLOBAL_IMPLICIT:
|
||||||
if (!c->u->u_ste->ste_unoptimized)
|
if (c->u->u_ste->ste_type == FunctionBlock &&
|
||||||
|
!c->u->u_ste->ste_unoptimized)
|
||||||
optype = OP_GLOBAL;
|
optype = OP_GLOBAL;
|
||||||
break;
|
break;
|
||||||
case GLOBAL_EXPLICIT:
|
case GLOBAL_EXPLICIT:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue