| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -123,6 +123,61 @@ | |||
| 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'", '0', 'None', '1') | ||
| 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 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -853,6 +853,7 @@ def test_remove_unused_consts_extended_args(self): | |||
| 853 | 853 | eval(compile(code, "file.py", "exec"), g) | |
| 854 | 854 | exec(code, g) | |
| 855 | 855 | f = g['f'] | |
| 856 | + # Issue #126072: None is no longer the first element in co_consts | ||
| 856 | 857 | expected = tuple(['', 1] + [f't{i}' for i in range(N)]) | |
| 857 | 858 | self.assertEqual(f.__code__.co_consts, expected) | |
| 858 | 859 | expected = "".join(expected[2:]) | |
@@ -1246,6 +1247,7 @@ def return_genexp(): | |||
| 1246 | 1247 | y) | |
| 1247 | 1248 | genexp_lines = [0, 4, 2, 0, 4] | |
| 1248 | 1249 | ||
| 1250 | + # Issue #126072: None is no longer the first element in co_consts | ||
| 1249 | 1251 | genexp_code = return_genexp.__code__.co_consts[0] | |
| 1250 | 1252 | code_lines = self.get_code_lines(genexp_code) | |
| 1251 | 1253 | self.assertEqual(genexp_lines, code_lines) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -84,6 +84,7 @@ def inner(): | |||
| 84 | 84 | return x | |
| 85 | 85 | return inner() % 2 | |
| 86 | 86 | ||
| 87 | + # Issue #126072: None is no longer the first element in co_consts | ||
| 87 | 88 | inner_code = mod_two.__code__.co_consts[0] | |
| 88 | 89 | assert isinstance(inner_code, types.CodeType) | |
| 89 | 90 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments