summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 08718d8..e3f74e9f 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1507,11 +1507,15 @@ def getclosurevars(func):
global_vars = {}
builtin_vars = {}
unbound_names = set()
- for name in code.co_names:
- if name in ("None", "True", "False"):
- # Because these used to be builtins instead of keywords, they
- # may still show up as name references. We ignore them.
- continue
+ global_names = set()
+ for instruction in dis.get_instructions(code):
+ opname = instruction.opname
+ name = instruction.argval
+ if opname == "LOAD_ATTR":
+ unbound_names.add(name)
+ elif opname == "LOAD_GLOBAL":
+ global_names.add(name)
+ for name in global_names:
try:
global_vars[name] = global_ns[name]
except KeyError: