homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Ryan Fox
Recipients Ryan Fox
Date 2016年03月17日.07:40:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1458200430.96.0.916440482942.issue26577@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016年03月17日 07:40:30Ryan Foxsetrecipients: + Ryan Fox
2016年03月17日 07:40:30Ryan Foxsetmessageid: <1458200430.96.0.916440482942.issue26577@psf.upfronthosting.co.za>
2016年03月17日 07:40:30Ryan Foxlinkissue26577 messages
2016年03月17日 07:40:30Ryan Foxcreate

AltStyle によって変換されたページ (->オリジナル) /