Skip to content

Commit 5aca797

Browse files
author
Michael Howitz
authored
Improve the inspect PR. (#256)
As the PR is already merged here a PR to improve it a bit further.
1 parent c8eca66 commit 5aca797

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

CHANGES.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Features
1818
Fixes
1919
+++++
2020

21-
- Restrict access to some attributes accessible via the ``inspect`` module.
21+
- Forbid using some attributes providing access to restricted Python internals.
2222

2323

2424
6.0 (2022-11-03)

src/RestrictedPython/transformer.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,50 @@
6363
'breakpoint',
6464
])
6565

66-
# inspect attributes. See also
67-
# https://docs.python.org/3/library/inspect.html
66+
# Attributes documented in the `inspect` module, but defined on the listed
67+
# objects. See also https://docs.python.org/3/library/inspect.html
6868
INSPECT_ATTRIBUTES = frozenset([
69-
# traceback
69+
# on traceback objects:
7070
"tb_frame",
71+
# "tb_lasti", # int
72+
# "tb_lineno", # int
7173
"tb_next",
72-
# code
73-
"co_code",
74-
# frame
74+
# on frame objects:
7575
"f_back",
7676
"f_builtins",
7777
"f_code",
7878
"f_globals",
79+
# "f_lasti", # int
80+
# "f_lineno", # int
7981
"f_locals",
8082
"f_trace",
81-
# generator
83+
# on code objects:
84+
# "co_argcount", # int
85+
"co_code",
86+
# "co_cellvars", # tuple of str
87+
# "co_consts", # tuple of str
88+
# "co_filename", # str
89+
# "co_firstlineno", # int
90+
# "co_flags", # int
91+
# "co_lnotab", # mapping between ints and indices
92+
# "co_freevars", # tuple of strings
93+
# "co_posonlyargcount", # int
94+
# "co_kwonlyargcount", # int
95+
# "co_name", # str
96+
# "co_qualname", # str
97+
# "co_names", # str
98+
# "co_nlocals", # int
99+
# "co_stacksize", # int
100+
# "co_varnames", # tuple of str
101+
# on generator objects:
82102
"gi_frame",
103+
# "gi_running", # bool
83104
"gi_code",
84105
"gi_yieldfrom",
85-
# coroutine
106+
# on coroutine objects:
86107
"cr_await",
87108
"cr_frame",
109+
# "cr_running", # bool
88110
"cr_code",
89111
"cr_origin",
90112
])

0 commit comments

Comments
 (0)