|
66 | 66 | flags: 67 |
67 | 67 | consts: ('None',) |
68 | 68 |
|
| 69 | +>>> def optimize_away(): |
| 70 | +... 'doc string' |
| 71 | +... 'not a docstring' |
| 72 | +... 53 |
| 73 | +... 0x53 |
| 74 | +
|
| 75 | +>>> dump(optimize_away.__code__) |
| 76 | +name: optimize_away |
| 77 | +argcount: 0 |
| 78 | +kwonlyargcount: 0 |
| 79 | +names: () |
| 80 | +varnames: () |
| 81 | +cellvars: () |
| 82 | +freevars: () |
| 83 | +nlocals: 0 |
| 84 | +flags: 67 |
| 85 | +consts: ("'doc string'", 'None') |
| 86 | +
|
69 | 87 | >>> def keywordonly_args(a,b,*,k1): |
70 | 88 | ... return a,b,k1 |
71 | 89 | ... |
|
84 | 102 |
|
85 | 103 | """ |
86 | 104 |
|
87 | | -import textwrap |
88 | 105 | import unittest |
89 | 106 | import weakref |
90 | | -import warnings |
91 | 107 | from test.support import run_doctest, run_unittest, cpython_only |
92 | 108 |
|
93 | 109 |
|
@@ -118,44 +134,6 @@ def test_newempty(self): |
118 | 134 | self.assertEqual(co.co_name, "funcname") |
119 | 135 | self.assertEqual(co.co_firstlineno, 15) |
120 | 136 |
|
121 | | - def dump(self, co): |
122 | | - dump = {} |
123 | | - for attr in ["name", "argcount", "kwonlyargcount", "names", "varnames", |
124 | | - "cellvars", "freevars", "nlocals", "flags"]: |
125 | | - dump[attr] = getattr(co, "co_" + attr) |
126 | | - dump['consts'] = tuple(consts(co.co_consts)) |
127 | | - return dump |
128 | | - |
129 | | - def test_optimize_away(self): |
130 | | - ns = {} |
131 | | - with warnings.catch_warnings(): |
132 | | - warnings.filterwarnings('ignore', category=SyntaxWarning) |
133 | | - exec(textwrap.dedent(''' |
134 | | - def optimize_away(): |
135 | | - 'doc string' |
136 | | - 'not a docstring' |
137 | | - 53 |
138 | | - 0x53 |
139 | | - b'bytes' |
140 | | - 1.0 |
141 | | - True |
142 | | - False |
143 | | - None |
144 | | - ... |
145 | | - '''), ns) |
146 | | - |
147 | | - self.assertEqual(self.dump(ns['optimize_away'].__code__), |
148 | | - {'name': 'optimize_away', |
149 | | - 'argcount': 0, |
150 | | - 'kwonlyargcount': 0, |
151 | | - 'names': (), |
152 | | - 'varnames': (), |
153 | | - 'cellvars': (), |
154 | | - 'freevars': (), |
155 | | - 'nlocals': 0, |
156 | | - 'flags': 67, |
157 | | - 'consts': ("'doc string'", 'None')}) |
158 | | - |
159 | 137 |
|
160 | 138 | class CodeWeakRefTest(unittest.TestCase): |
161 | 139 |
|
|
0 commit comments