|
17 | 17 | freevars: ()
|
18 | 18 | nlocals: 2
|
19 | 19 | flags: 3
|
20 |
| -consts: ('None', '<code object g>') |
| 20 | +consts: ('<code object g>',) |
21 | 21 |
|
22 | 22 | >>> dump(f(4).__code__)
|
23 | 23 | name: g
|
|
86 | 86 | cellvars: ()
|
87 | 87 | freevars: ()
|
88 | 88 | nlocals: 0
|
89 |
| -flags: 3 |
| 89 | +flags: 67108867 |
90 | 90 | consts: ("'doc string'", 'None')
|
91 | 91 |
|
92 | 92 | >>> def keywordonly_args(a,b,*,k1):
|
|
123 | 123 | flags: 3
|
124 | 124 | consts: ('None',)
|
125 | 125 |
|
| 126 | +>>> def has_docstring(x: str): |
| 127 | +... 'This is a one-line doc string' |
| 128 | +... x += x |
| 129 | +... x += "hello world" |
| 130 | +... # co_flags should be 0x4000003 = 67108867 |
| 131 | +... return x |
| 132 | +
|
| 133 | +>>> dump(has_docstring.__code__) |
| 134 | +name: has_docstring |
| 135 | +argcount: 1 |
| 136 | +posonlyargcount: 0 |
| 137 | +kwonlyargcount: 0 |
| 138 | +names: () |
| 139 | +varnames: ('x',) |
| 140 | +cellvars: () |
| 141 | +freevars: () |
| 142 | +nlocals: 1 |
| 143 | +flags: 67108867 |
| 144 | +consts: ("'This is a one-line doc string'", "'hello world'") |
| 145 | +
|
| 146 | +>>> async def async_func_docstring(x: str, y: str): |
| 147 | +... "This is a docstring from async function" |
| 148 | +... import asyncio |
| 149 | +... await asyncio.sleep(1) |
| 150 | +... # co_flags should be 0x4000083 = 67108995 |
| 151 | +... return x + y |
| 152 | +
|
| 153 | +>>> dump(async_func_docstring.__code__) |
| 154 | +name: async_func_docstring |
| 155 | +argcount: 2 |
| 156 | +posonlyargcount: 0 |
| 157 | +kwonlyargcount: 0 |
| 158 | +names: ('asyncio', 'sleep') |
| 159 | +varnames: ('x', 'y', 'asyncio') |
| 160 | +cellvars: () |
| 161 | +freevars: () |
| 162 | +nlocals: 3 |
| 163 | +flags: 67108995 |
| 164 | +consts: ("'This is a docstring from async function'", 'None') |
| 165 | +
|
| 166 | +>>> def no_docstring(x, y, z): |
| 167 | +... return x + "hello" + y + z + "world" |
| 168 | +
|
| 169 | +>>> dump(no_docstring.__code__) |
| 170 | +name: no_docstring |
| 171 | +argcount: 3 |
| 172 | +posonlyargcount: 0 |
| 173 | +kwonlyargcount: 0 |
| 174 | +names: () |
| 175 | +varnames: ('x', 'y', 'z') |
| 176 | +cellvars: () |
| 177 | +freevars: () |
| 178 | +nlocals: 3 |
| 179 | +flags: 3 |
| 180 | +consts: ("'hello'", "'world'") |
126 | 181 | """
|
127 | 182 |
|
128 | 183 | import copy
|
|
0 commit comments