|
发表于 2022-3-25 17:50:48
|
显示全部楼层
- #!/usr/bin/env python
- from pathlib import Path
- #from glob import iglob
- import dis
- import sys
- def gather(acc, co):
- for instr in dis.get_instructions(co):
- acc.add(instr.opname)
- for const in co.co_consts:
- if hasattr(const, 'co_code'):
- gather(acc, const)
- cov = set()
- for t in Path('cpython/Lib/test').glob('**/*.py'):
- with t.open('rb') as src:
- try:
- co = compile(src.read(), str(t), 'exec')
- gather(ops := set(), co)
- # print(len(ops), t.name)
- cov |= ops
- except Exception as e:
- print(t.name, e)
- print(len(cov), len(dis.opmap))
- print(sys.version)
复制代码104 106
3.11.0a6+ (heads/main:b68431fadb, Mar 25 2022, 09:05:27) [GCC 9.3.0]
官方 tests 也没用遍所有 bytecode 么… |
|