Title: gh-104240: make _PyCompile_CodeGen support different compilation modes by iritkatriel · Pull Request #104241 · python/cpython · GitHub
Open Graph Title: gh-104240: make _PyCompile_CodeGen support different compilation modes by iritkatriel · Pull Request #104241 · python/cpython
X Title: gh-104240: make _PyCompile_CodeGen support different compilation modes by iritkatriel · Pull Request #104241 · python/cpython
Description: With this PR we can do this: from _testinternalcapi import compiler_codegen, optimize_cfg, assemble_code_object import ast import opcode import textwrap import types a = ast.parse("(x+y)/2", mode='eval') filename = "myfile.py" eval_mode = 1 # 0=exec, 1=eval, 2=single insts = compiler_codegen(a, filename, 0, eval_mode) consts = list(range(5)) insts = optimize_cfg(insts, consts) metadata = { 'name' : 'avg', 'qualname' : 'stats.avg', 'consts' : [2], 'argcount' : 0, 'names' : {'x' : 0, 'y' : 1}, 'varnames' : {}, } from test.test_compiler_assemble import IsolatedAssembleTests IsolatedAssembleTests().complete_metadata(metadata) co = assemble_code_object(filename, insts, metadata) for x,y in [(3, 4), (-100, 200), (10, 18)]: f = types.FunctionType(co, {'x': x, 'y': y}) print(f'avg of {x} and {y} is {f()}') Issue: gh-104240
Open Graph Description: With this PR we can do this: from _testinternalcapi import compiler_codegen, optimize_cfg, assemble_code_object import ast import opcode import textwrap import types a = ast.parse("(x+y)/2&qu...
X Description: With this PR we can do this: from _testinternalcapi import compiler_codegen, optimize_cfg, assemble_code_object import ast import opcode import textwrap import types a = ast.parse("(x+y)/...
Opengraph URL: https://github.com/python/cpython/pull/104241
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:ddeb89ec-181f-27f5-8561-38c25effb517 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E478:9D4F4:85E62C:B6C3FD:6969DDEA |
| html-safe-nonce | 34418248d46e9726714bc3a502dcf3f5a89b14438dec821705a5429f9ab83a1c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDc4OjlENEY0Ojg1RTYyQzpCNkMzRkQ6Njk2OURERUEiLCJ2aXNpdG9yX2lkIjoiNzE0NjU0ODg4NzYzNDQzNTU2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6d39b4e321e7b3044e3f7911a503016f967f53c3e3e005190798c0aec89dd93f |
| hovercard-subject-tag | pull_request:1340831061 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/104241/files |
| twitter:image | https://avatars.githubusercontent.com/u/1055913?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1055913?s=400&v=4 |
| og:image:alt | With this PR we can do this: from _testinternalcapi import compiler_codegen, optimize_cfg, assemble_code_object import ast import opcode import textwrap import types a = ast.parse("(x+y)/2&qu... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width