Message261897
If a variable 'x' exists in the global or local scope, and a function (also defined in the same scope as 'x', or lower) refers only to a member named 'x' of an object, inspect.getclosurevars will include a reference to the variable, rather than the member.
Okay, that's kind of confusing to describe, so here's a small example in code form:
import inspect
class Foo:
x = int()
x = 1
f = Foo()
assert(f.x != x)
func = lambda: f.x == 0
assert(func())
cv = inspect.getclosurevars(func)
assert(cv.globals['f'] == f)
assert(cv.globals.get('x') != x) # <--- Assertion fails
It is expected that 'x' would not exist in cv.globals, since func does not refer to it. Also, there should be a 'f.x' included somewhere in the ClosureVariables object returned. |
|
| Date |
User |
Action |
Args |
| 2016-03-17 07:40:30 | Ryan Fox | set | recipients:
+ Ryan Fox |
| 2016-03-17 07:40:30 | Ryan Fox | set | messageid: <1458200430.96.0.916440482942.issue26577@psf.upfronthosting.co.za> |
| 2016-03-17 07:40:30 | Ryan Fox | link | issue26577 messages |
| 2016-03-17 07:40:30 | Ryan Fox | create | |
|