Compare commits

...

240 Commits

Author SHA1 Message Date
rocky
ad00b9a4ee Use xdis pattr extraction for LOAD_NAME 2023-04-15 07:31:35 -04:00
rocky
551e428086 Go over stdlib test for 2.{6,7} 2023-04-08 22:10:21 -04:00
R. Bernstein
cd0049933f Merge pull request #440 from andrem-eberle/master
Tentative fix for issue #437.
2023-04-08 20:37:31 -04:00
Andre Eberle
7f3c1fa3a4 Tentative fix for issue #437. I added a new set of rules in ifelsestmt.py to check against for offsets. Seems to have fixed current issue. The result output is switching nested if-else-if-else-etc to a chain of if-elif-elif now, but semantically seems correct. 2023-04-08 16:54:55 -04:00
rocky
f76c35c902 Slightly nicer docstring detection for closure 2023-03-25 02:20:26 -04:00
rocky
82963cdf2c Preserve docstring in closures..
This change synchronized from decompyle3
2023-03-24 20:31:49 -04:00
rocky
a20972dd12 xdis PYTHON_VERSION removal 2023-02-26 19:29:08 -05:00
rocky
18b5934b2d Allow xdis 6.1.0 2023-02-26 19:21:30 -05:00
R. Bernstein
982abe0980 Merge pull request #430 from rocky/sync-with-decompyle3
Synch with decompyle3 code a little bit
2023-01-19 05:10:20 -05:00
rocky
41d1ba31f3 Synch with decompyle3 code a little bit 2023-01-19 04:31:19 -05:00
rocky
e03f4cfe43 Try adding no blank templates 2023-01-18 22:23:06 -05:00
R. Bernstein
53a5e03a8f Merge pull request #429 from rocky/reinstate-pos-args
Reinstate pos_args in CALL_METHOD
2023-01-18 21:23:23 -05:00
rocky
7c99564640 Reinstate pos_args in CALL_METHOD 2023-01-18 21:01:11 -05:00
rocky
931abc5726 self.opc.version -> self.opc.version_tuple
The next release of xdis will no longer support self.opc.version (a
float value which doesn't work in the presense of 3.10 and above)
2023-01-18 17:08:39 -05:00
rocky
2b3cd696db 3.0 set comprehension bug 2023-01-16 03:50:50 -05:00
rocky
50697bb79e Improve set comprehension for Python 3.0 2023-01-16 03:40:55 -05:00
R. Bernstein
137dd64a46 Merge pull request #427 from rocky/make-fn-or-closure-with-annotatation
try to be more honest about MAKE_{FUNCTION,CLOSURE}
2023-01-16 02:12:13 -05:00
rocky
9a7eb0ad0a try to be more honest about MAKE_{FUNCTION,CLOSURE} 2023-01-16 01:45:37 -05:00
rocky
154dabfcef Handle Python 3.4 MAKE_CLOSURE fns ...
Is done just like Python 3.3
2023-01-14 09:54:48 -05:00
rocky
42d26ccbd7 Bump version 2023-01-14 06:21:12 -05:00
rocky
73a4c0be78 Use 3.7.16 for master version 2023-01-14 02:49:43 -05:00
rocky
92830c2eae Newer setuptools 2023-01-14 02:22:53 -05:00
rocky
090570cd34 3.4-3.5 MAKE_CLOSURE with annotate
Docs lie about annnotation args. Slight adjustment here.
More is probably needed.
2023-01-14 02:20:59 -05:00
rocky
16914feb12 Get ready for release 3.9.0 2022-12-22 23:57:31 -05:00
rocky
1ffc58ac6d Bump list of newest versions 2022-12-22 22:44:30 -05:00
rocky
77bbe49c32 Change Python versions used in testing
to match what works on workflows CI
2022-12-20 10:27:11 -05:00
rocky
e8d4d383c6 pycharm lint, isort & black 2022-12-01 17:36:00 -05:00
rocky
9f1514a2dd Update copyrights 2022-11-27 05:18:45 -05:00
rocky
6110b3a095 Add isort configuration 2022-11-27 04:50:27 -05:00
rocky
d1911d2487 More lint 2022-11-27 04:14:46 -05:00
rocky
55bb5640ee More lint 2022-11-27 03:52:43 -05:00
rocky
cab53b49b5 Small grammar and spelling errors 2022-11-27 03:25:55 -05:00
rocky
514b0d0b0c Sync from decompyle3 2022-11-06 01:24:28 -05:00
R. Bernstein
283e493270 Merge pull request #419 from jameshilliard/token-opc
Replace remaining self.opc with token.opc
2022-11-05 20:59:47 -04:00
James Hilliard
e08324d85c Replace remaining self.opc with token.opc 2022-11-05 19:39:31 -04:00
R. Bernstein
03282d3dd9 Merge pull request #418 from jameshilliard/fix-status-msg
Fix status_msg args
2022-11-05 19:23:35 -04:00
rocky
207dc0b506 opc field in while1 reduction is off of token...
not self (parse)
2022-11-05 19:20:16 -04:00
James Hilliard
6787a582cf Fix status_msg args
Fixes:
uncompyle6/bin/uncompile.py", line 201, in main_bin
    mess = status_msg(do_verify, *result)
TypeError: status_msg() takes 5 positional arguments but 6 were given
2022-11-05 18:59:13 -04:00
R. Bernstein
647df7140c Merge pull request #416 from jameshilliard/fix-parsers-version
Fix ImportError: cannot import name PYTHON_VERSION
2022-11-05 18:35:30 -04:00
James Hilliard
ab508e1ec9 Fix ImportError: cannot import name PYTHON_VERSION 2022-11-05 17:17:24 -04:00
rocky
8843686b49 Add generator expression Python 3.0 .. 3.2 2022-11-05 10:31:00 -04:00
rocky
9d1cf50c5e Add generator expression Python 3.0 .. 3.2 2022-11-05 10:15:45 -04:00
rocky
98626ee162 Misc linting 2022-11-05 05:04:25 -04:00
R. Bernstein
2884068c61 Merge pull request #415 from jameshilliard/parsererror2
Add missing ParserError2 in make_functions36
2022-11-05 01:09:05 -04:00
rocky
57d2386cc3 Fix another 3.0 list comprehension parse 2022-11-05 00:27:05 -04:00
James Hilliard
ce66b12176 Add missing ParserError2 in make_functions36 2022-11-04 23:42:28 -04:00
rocky
f59d0bf306 Misc lint 2022-11-04 03:54:01 -04:00
rocky
4959c76694 More 3.0 list comprehension bug fixes 2022-11-04 02:05:34 -04:00
rocky
766618ba48 Alow 3.0 setup 2022-11-04 00:53:45 -04:00
rocky
0be3fc657b Sync with 3.3-3.5 branch 2022-11-04 00:49:24 -04:00
rocky
d0a98bdbc6 Correct 3.0 list comprehension parsing 2022-11-04 00:42:50 -04:00
rocky
9ecdf12667 Some small typos and lint 2022-11-03 12:27:55 -04:00
rocky
f9aa2410d1 More float -> tuple version corrections 2022-11-03 12:20:10 -04:00
rocky
d6dcaff240 Fixes #414 2022-11-03 12:02:34 -04:00
rocky
5b3ea47bac Correct long-literals for Python 2.7 2022-10-16 19:33:51 -04:00
rocky
bb9b9fb4b3 Improve "if/else" in "for" test 2022-10-16 18:24:48 -04:00
rocky
1819fc8944 ifelsetmt - jump back is only allowed inside loops 2022-10-16 17:50:58 -04:00
R. Bernstein
8e6a0b01fa Merge pull request #413 from Berbe/for-loop
Fix: CONTINUE in else block in a for loop
2022-10-16 17:46:26 -04:00
Berbe
512c500810 Add: Tests: CONTINUE in else block in a for loop 2022-10-10 20:33:19 +02:00
rocky
976705fc0a Add: Python 2.7: ifelsestmtc 2022-10-10 04:30:48 +02:00
rocky
ae46ccf6d3 Go over 2.7 stdlib exclusions 2022-09-30 20:09:41 -04:00
rocky
a1cc0aab37 Move test: all() not in 2.4 2022-09-30 03:45:24 -04:00
rocky
0c7427069e strings need quotes in ADD_VALUE instructions 2022-09-30 03:33:47 -04:00
rocky
2264ccb1d5 A partial reduce-action sync with decompyle3
Start us add _check prefixes and _invalid to the end of check methods
2022-09-30 02:45:52 -04:00
rocky
3bd3029169 Confused == with = 2022-09-29 20:08:07 -04:00
rocky
ad1fa98870 Detect Python 2.7 weird "for-block" bytecode
It has an unnecessary JUMP_ABSOLUTE to a JUMP_LOOP

Fixes #408
2022-09-27 08:58:35 -04:00
rocky
8c85260852 Lint-like changes from VSCode
Also allow 3.11 to run this
2022-09-21 08:29:06 -04:00
rocky
62b816c60b Correct a signature return 2022-09-21 02:08:08 -04:00
rocky
d0f173a620 Lint from pycharm 2022-09-21 01:53:56 -04:00
rocky
7c3aff19af "async for"s can has pass blocks 2022-09-21 00:27:40 -04:00
rocky
be9af85e16 Hande Python 3.5 make_function() semantic action
Fixes #409
2022-09-21 00:19:37 -04:00
rocky
6c116fe4f9 Bump default master Python version 2022-09-20 17:35:33 -04:00
rocky
62760eb556 Deal with 2.x EXTENDED_ARGS on JUMP_ABSOLUTE
in scanner2's "continue" detection

Fixes #310
2022-09-18 21:12:27 -04:00
rocky
600688a65d Sync with decompyle3 2022-09-17 10:54:09 -04:00
rocky
a68f440d6f Sync with decompyle3
Better PyPy 3.7 tolerance
2022-09-17 01:59:42 -04:00
rocky
f913306070 Use github xdis...
So we pick up newer versions of Python 3.{7,8,9}.14 & 3.10.7
2022-09-16 19:03:00 -04:00
rocky
04df8a98fb uncompyle6.disasm -> uncompyle6.code_fns 2022-09-16 15:46:46 -04:00
rocky
4b2a2e218a Misc lint stuff from pycharm...
that has been applied to decompyle3 already
2022-09-16 15:38:13 -04:00
rocky
4260deea11 Tidy ifelsemstmt check 2022-08-29 05:46:46 -04:00
R. Bernstein
200250df56 Merge pull request #406 from tangboxuan/master
Fix offset of extended argument instruction
2022-08-24 05:51:41 -04:00
rocky
765b0149ea iftstmt reduce rule for 2.6:
In ifsmt there can be a JUMP_ABSOLUTE right before the endif and a jump
the endif doesn't fall through to the place after the endif.
2022-08-24 05:33:22 -04:00
Bo Xuan
2f3b5e53d4 Add test case 2022-08-24 16:19:39 +08:00
rocky
3cc51aa37f Reduce 2.6 excluded tests 2022-08-23 21:51:33 -04:00
R. Bernstein
19152e7ed8 Merge pull request #407 from rocky/python-2.6-if-fixup
Push reducechecks from 2.7 into 2.6
2022-08-23 21:41:16 -04:00
rocky
71b1446c9c Push reducechecks from 2.7 into 2.6
Some adaption is needed. These rules may also help earlier 2.x Python as well
2022-08-23 21:36:55 -04:00
rocky
14aa0ce8f0 sort a list 2022-08-23 20:17:06 -04:00
rocky
dfd8762dbd Update 2.6 exclude list 2022-08-23 17:26:45 -04:00
rocky
21b4d52a77 Correct 2.6 erroneous ifelse detection 2022-08-23 16:50:50 -04:00
rocky
9da3e4b3c0 For some 2.6 test PYTHON needs to be set to pytest 2022-08-23 08:11:06 -04:00
rocky
d73d0dd11a PYTHON_VERSION -> PYTHON_VERSION_TRIPLE 2022-08-23 06:54:23 -04:00
Bo Xuan
81633b3c1c Fix offset of extended argument instruction 2022-08-23 14:18:31 +08:00
rocky
4120213710 Update link which has gone stale 2022-08-14 20:32:47 -04:00
rocky
610f2c827c Remove 3.6-specific iflastsmt reduce check
Fixes #344
2022-07-07 06:54:05 -04:00
rocky
5a4136a7f6 Some limited support for 3.8 "=" specifier 2022-07-06 13:00:52 -04:00
rocky
cc4ea47d24 Use ifelsetmt reduction rule on 2.7 2022-07-04 07:56:44 -04:00
rocky
85ba8352ba Port over some recent decompyle3 3.8 fixes 2022-06-26 04:26:15 -04:00
rocky
7f798541f0 Python 3.8 while and whileTrue loops 2022-06-16 15:42:51 -04:00
rocky
7fb483c566 Sync up with decompile3's 3.8 try/else handling 2022-06-08 12:49:23 -04:00
rocky
6597737709 Merge branch 'master' of github.com:rocky/python-uncompyle6 2022-05-28 15:48:28 -04:00
rocky
c08ab41afd Go over what constitutes a bug, yet again 2022-05-28 15:45:51 -04:00
rocky
2cc58fec97 Note narrowing bug 2022-05-21 12:30:21 -04:00
rocky
8f7f0be7fa Administrivia
Workflows CI: go back to released versions rather than github versions
pyenv-newest-versions: updaed to use newest Python releases
pypy38.py: fix wrong package name import
3.6-exclude.sh: update and advance
2022-05-20 06:44:20 -04:00
rocky
3f4e85695e Reduce 3.7 exclusion tests 2022-05-14 22:24:25 -04:00
rocky
5c29b9a5e5 remove \n in lambda; 2.6 grammar cleanup 2022-05-14 20:28:24 -04:00
rocky
fa9cc4c669 Correct 2.5-7 relative import formatting 2022-05-14 19:35:24 -04:00
rocky
656a9aa290 Bugs in 2.x relative import '.' and 1.x bytecode 2022-05-14 17:46:48 -04:00
rocky
021810bb2c Correct 2.x formatting "slice2" nonterminal 2022-05-14 16:54:50 -04:00
rocky
223804ac1f semi-black scanner26.py 2022-05-14 09:51:50 -04:00
rocky
3a9fa652b4 Partial sync of 3.7 & 3.8 scanner with decompyle3 2022-05-14 08:42:04 -04:00
rocky
87fb83de08 Add missing 3.7 "import_from37" template 2022-05-14 02:59:15 -04:00
R. Bernstein
fbe4be3bb0 Merge pull request #399 from rocky/genexpr-3.6
3.6 async hacking
2022-05-07 07:10:33 -04:00
rocky
9b80663529 3.6 async hacking 2022-05-07 07:01:39 -04:00
rocky
dae00e9b0b More 3.6 "async for" 2022-05-06 15:15:05 -04:00
R. Bernstein
3cbe7ba5d7 Merge pull request #398 from rocky/LOAD_ARG_for36
Use LOAD_ARG in 3.6
2022-05-06 13:45:52 -04:00
rocky
cca015c5d6 Use LOAD_ARG in 3.6 2022-05-06 12:53:55 -04:00
rocky
cc47d61efa Better 3.6 set comprehensions 2022-05-06 07:30:56 -04:00
R. Bernstein
b421b00b53 Merge pull request #397 from rocky/LOAD_ARG
Classify LOAD_ARG as LOAD_FAST of .0
2022-05-06 03:06:19 -04:00
rocky
92b8d9c508 Grammar lint adjustments 2022-05-06 03:02:30 -04:00
rocky
f5043408ec Start rolling in LOAD_ARG for 3.7+ 2022-05-06 02:41:02 -04:00
rocky
8576117d00 Fix More 3.6 async parsing
... all from 3.6 test_coroutines.py.

More bugs remain
2022-05-05 07:36:06 -04:00
rocky
c5efec1e6f Fox some 3.6 async_forelse parsing 2022-05-05 07:09:39 -04:00
rocky
f9a1f6fcd9 Sync 3.7 async_forelse with decompyle3 2022-05-05 06:47:49 -04:00
rocky
c9f33edde4 Handle 3.6 "async for" better 2022-05-04 19:21:07 -04:00
rocky
9dd4a53ff8 Fix 3.6 async parsing 2022-05-04 04:27:38 -04:00
rocky
d62310f799 Correct 3.6ish dictionary literals printing 2022-05-03 12:19:43 -04:00
rocky
ac862b4566 In Python 2.2- preserve line numbers 2022-05-03 07:15:18 -04:00
rocky
e94e9379c0 Bang on version 1.0-1.4 Python 2022-05-02 22:03:52 -04:00
rocky
5df57489b4 CI woes - need new xdis
Remove 1.0 os.pyc until I can investigate.
It works locally though
2022-04-30 20:50:28 -04:00
rocky
9aba1cc3af Bytecode 1.x fixes 2022-04-30 20:36:43 -04:00
rocky
eba0d37d0f Improve Python 1.x decompiling
Still has bugs, but is much better.
2022-04-30 05:54:22 -04:00
rocky
5e1ba2baa1 Split long lines in n_const_list 2022-04-28 18:03:15 -04:00
rocky
f35231a6f5 Correct bug in long literal replacement for 2.6-7 2022-04-28 17:28:09 -04:00
rocky
37ea469ce6 One more 2.4 test 2022-04-28 17:11:17 -04:00
rocky
8e5faa933f Handle long 2.x bytecode literals more efficiently 2022-04-27 13:47:56 -04:00
rocky
cfd6166d8d Small doc corrections 2022-04-27 05:07:07 -04:00
rocky
a356a8e0ee Reinstante pyenvlib 2022-04-27 03:39:05 -04:00
rocky
152de50f90 Revise docstring explaiing pydisassemble 2022-04-26 18:12:26 -04:00
rocky
1c49eb5989 Revise what pydisassemble is about 2022-04-26 18:09:16 -04:00
rocky
c25fa61e33 Start handling BUILD_MAP (a class of dict) 2022-04-26 15:37:42 -04:00
R. Bernstein
81ff994a41 Merge pull request #394 from rocky/long-collection-python3
Long collection python3
2022-04-26 03:18:16 -04:00
rocky
d48801964c Use attr insead of pattrr for non-strings 2022-04-26 03:13:27 -04:00
rocky
4879a60ecc Some bugs creating token stream ..
from instructions.
2022-04-25 17:39:39 -04:00
rocky
bf58fb9cf2 WIP - extend fast long-literals into older Python3 2022-04-25 08:06:46 -04:00
rocky
c6642f5899 Revise "ingest" docstring 2022-04-25 07:42:56 -04:00
R. Bernstein
13266d1b56 Merge pull request #393 from rocky/speedup-long-collections
Speedup long collections
2022-04-24 18:00:11 -04:00
rocky
e564ac3ab1 Go over long-literal test 2022-04-24 17:50:32 -04:00
rocky
8cdf741b62 Bugs in long-literal handlin
Move n_dict to n_actions and special case n_const_list.
Generalize build_collection out of 3.7+ and into all Pythons
2022-04-24 17:38:35 -04:00
rocky
371138cfbc handle long literal constants faster 2022-04-24 13:11:20 -04:00
rocky
464801bcb3 Correct type annotation on decompile()
Fixes #391
2022-04-21 20:10:33 -04:00
rocky
f3ac70d0ea test tweak again 2022-04-21 05:34:15 -04:00
rocky
433d7003e0 Add "transfrormd_by" param to SyntaxTree
This aligns code more with decompyle3
2022-04-21 05:25:14 -04:00
rocky
c88d9de316 Correct 3.7 "impor"t and "from .. import" 2022-04-20 20:03:28 -04:00
rocky
e2ff909603 Split off (semantic) nonterminal print actions 2022-04-19 16:42:48 -04:00
rocky
3662f3e8c6 Fold in some decompile changes 2022-04-17 12:20:03 -04:00
rocky
c806ef59c6 Update scanner demo code 2022-04-17 11:41:19 -04:00
rocky
f8ae674890 Split out comprehension code..
sync with decompile a little better
2022-04-17 10:52:56 -04:00
rocky
1c1752d6d6 Bump testing version ...
pyston 2.3 testing
2022-04-17 10:29:23 -04:00
rocky
420d22c094 Correct for pypy 3.7 2022-04-15 08:36:42 -04:00
rocky
faac21d1e4 Bump testing versions 2022-04-15 08:25:38 -04:00
rocky
a26ac79d0f Sync up decompyle3 customize37 somewhat 2022-04-15 08:22:45 -04:00
rocky
1a673aba40 Reinstate a test 2022-04-13 03:05:04 -04:00
rocky
04510ac2f8 lambda formatting in f-string
In a formatted string using "lambda',  we should not add "\n".
For example in:
  f'{(lambda x:x)("8")!r}'

Adding a "\n" after "lambda x: x" will give an error message:
  SyntaxError: f-string expression part cannot include a backslash
2022-04-12 16:49:58 -04:00
rocky
a1fe069c8c Handle walrus operator
Or rather set precedence on call_stmt and expr_stmt

Adjust pytest test_single_compile so it works now
2022-04-12 05:21:13 -04:00
rocky
e7fd592313 Update bug template 2022-04-11 13:06:39 -04:00
rocky
728954295f Note that you can pay me for personal help 2022-04-10 13:02:58 -04:00
rocky
83ab85353b Remove a reference to an unset local variable
See also https://github.com/rocky/python-uncompyle6/pull/388
2022-04-09 02:29:44 -04:00
rocky
bc71bf7acd Shorten 10_complex.py
Runtime testing took too long because ranges were larger than needed
Also use newer convention for marking runable codes
2022-04-03 06:41:58 -04:00
rocky
9735453283 Small changes
test code for pysource and bump lastest testing Python versions
2022-04-01 03:11:59 -04:00
rocky
7f9014fb05 Add Table of Contents 2022-03-12 05:26:01 -05:00
rocky
e14b8dd496 Sync with decompyle3 2022-03-12 05:18:24 -05:00
rocky
aaa737672b Mention pydeinstaller 2022-03-12 04:56:33 -05:00
R. Bernstein
2198f9bbaa Update HOW-TO-REPORT-A-BUG.md 2022-03-12 04:52:11 -05:00
R. Bernstein
b7015b16b0 Update HOW-TO-REPORT-A-BUG.md 2022-03-12 04:49:33 -05:00
R. Bernstein
67bb8223d8 Update HOW-TO-REPORT-A-BUG.md 2022-03-12 04:48:07 -05:00
R. Bernstein
2faa7b0597 Update HOW-TO-REPORT-A-BUG.md 2022-03-12 04:43:08 -05:00
R. Bernstein
58f00b1e5b Update HOW-TO-REPORT-A-BUG.md 2022-03-12 04:39:39 -05:00
rocky
3d24de7ce5 __init__.py lint 2022-03-09 12:16:38 -05:00
R. Bernstein
b270f6eed7 Update HOW-TO-REPORT-A-BUG.md 2022-03-05 05:27:21 -05:00
R. Bernstein
e81d944c12 Update HOW-TO-REPORT-A-BUG.md 2022-03-05 05:26:26 -05:00
rocky
2718492001 spell check 2022-03-05 05:08:52 -05:00
R. Bernstein
68d6bc2fa1 Update HOW-TO-REPORT-A-BUG.md 2022-03-05 04:58:33 -05:00
rocky
884c15e84a Update toc 2022-03-05 04:57:55 -05:00
rocky
82456c15e1 Reduce check type for 2.5 and update bug reporting 2022-03-05 04:55:11 -05:00
rocky
09c10f51fa Revise README 2022-03-05 04:20:30 -05:00
rocky
3490389a66 Correct some Python 2.6 chain compare bugs 2022-03-05 04:03:27 -05:00
rocky
d366248b47 Some small variable-name changes 2022-03-04 04:47:38 -05:00
rocky
6f112ec5b2 Ensure no parens on subscript slice 2022-03-03 21:05:47 -05:00
rocky
219cb0606a MAKE_FUNCTION_8 -> MAKE_FUNCTION_CLOSURE
Clarity is important.
2022-02-27 10:29:53 -05:00
rocky
ce5207333f Remove TABLE_R0 - it hasn't been used in a while 2022-02-27 10:18:57 -05:00
rocky
f2a70a2758 Sync with decompyle3 for async "for"
More work is needed though
2022-01-18 15:25:51 -05:00
rocky
5b5fa310d9 Partial 3.8 async "for" fixes 2022-01-18 13:08:17 -05:00
rocky
88c0c03ee4 setcomprehension_walk3 -> closure_walk 2022-01-14 07:50:39 -05:00
rocky
a381b4663b Adapt for recent options changes in
-T option structure changed.
2022-01-09 16:01:32 -05:00
R. Bernstein
2fda52bf45 Merge pull request #382 from lostbeta/master
Fix version check comparison
2022-01-09 14:48:42 -05:00
lostBeta
415cba6978 Fix version check comparison 2022-01-09 18:52:48 +02:00
rocky
15761acd0d Revise options processing. Sync with decompyle3
We should now handle passing assembly options or functions and
subroutines more properly.

The "%P" and "%p" specifiers now allow lists of nonterminals like "%c"
and "%C" do.

version was bumped because top-level main parameter args change slightly.
2022-01-09 04:11:09 -05:00
R. Bernstein
1c0fc283b1 Merge pull request #381 from rocky/return-expr
ret_expr -> return_expr
2022-01-03 22:02:43 -05:00
rocky
deea74b6a8 ret_expr -> return_expr
This matches Python's AST a little more closely
2022-01-03 21:56:07 -05:00
R. Bernstein
7f42694c25 Merge pull request #380 from rocky/return_expr_lambda
return_lambda -> return_expr_lambda
2022-01-01 22:41:12 -05:00
rocky
3d5b6f4654 return_lambda -> return_expr_lambda
Except those places in 2.6ish code where it is simple a fancy RETURN_VALUE
2022-01-01 21:45:51 -05:00
rocky
51e32b88a4 Include 2.4_run, 2.5_run in testing 2021-12-31 11:39:57 -05:00
R. Bernstein
b7583dfb60 Merge pull request #379 from rocky/elif-transformation-with-continue
Elif transformation with continue
2021-12-31 11:32:23 -05:00
rocky
203139eafa Add tests, comment what's up with change..
and use isinstance()
2021-12-31 11:27:15 -05:00
R. Bernstein
9172f82bae Merge pull request #378 from dkw72n/wrong_type
Fix #377
2021-12-31 11:07:14 -05:00
dkw72n
d9de4ea245 Fix #377 2021-12-31 16:11:27 +08:00
rocky
3b96313fd8 Revise README.rst 2021-12-28 23:16:53 -05:00
R. Bernstein
2070208ca3 Update NEW_FEATURES.rst 2021-12-27 19:13:00 -05:00
rocky
88e169adca More verbiage on what we have and what's happened. 2021-12-27 16:28:28 -05:00
rocky
165115289a dict_unmap -> dict_unpack matches Python AST better 2021-12-26 19:03:58 -05:00
rocky
3234673422 mklambda -> lambda_body matches Python AST better
Note: we can't use "lambda" since that is a reserved word
2021-12-26 18:48:51 -05:00
rocky
23551ea70f unmap_dict -> dict_doublestar ...
This matches Python's AST (Dict) better. Variations or specializations
of an AST name, e.g. "unmap" should come at the end, not the beginning.
2021-12-23 22:57:15 -05:00
rocky
30aad42aae Sync with other versions 2021-12-23 16:46:25 -05:00
rocky
a3bc9bb32b Add operator precedence to -T output 2021-12-23 16:11:25 -05:00
rocky
8deb940b21 Update and revise HISTORY
Remove some of the older history and put a link to that which is nos
recorded in decompyle-2.4's history.
2021-12-22 21:49:38 -05:00
rocky
b3aaff0201 Sync pysource with decompyle3 2021-12-18 03:03:50 -05:00
rocky
da2314f5ae Part of the decompye3 loop "continue" fixes 2021-12-17 16:13:09 -05:00
rocky
16c900ff1d Propagate show_asm debug option down to functions 2021-12-17 06:07:18 -05:00
rocky
ed5346e526 Another pass clarifying what's okay as bug report 2021-11-30 03:33:20 -05:00
rocky
e718b794f3 Administrivia 2021-11-28 06:20:25 -05:00
rocky
03a71290e9 Admnistrivia
revise add-test.py
2021-11-24 15:12:53 -05:00
rocky
2c4acecc9d Start PyPy 3.8 support 2021-11-23 16:45:01 -05:00
rocky
2d5249f1d3 Small comment change 2021-11-23 07:31:37 -05:00
rocky
223b9e1d88 Extent METHOD_CALL_KW to PyPy 3.8 2021-11-23 07:23:23 -05:00
rocky
211c74c240 Better 3.7 CALL_METHOD_KW handling
- Handles positional args now
2021-11-23 05:06:48 -05:00
rocky
3a63847d22 Tweak last commit 2021-11-22 09:27:16 -05:00
rocky
2ed211e0d4 Some PyPY 3.7 support
* Handle CALL_METHOD_KW
* adjust PyPY 3.7 assert stmts
* misc administrivia
2021-11-21 14:04:34 -05:00
rocky
d752f63d12 PyPy 3.7 scanner bug 2021-11-21 00:06:45 -05:00
rocky
88dd5d7756 Remove one more float version test 2021-11-16 06:47:31 -05:00
rocky
4d351e31cd Administrivia: workflows CI 2021-11-07 10:23:12 -05:00
rocky
69387c4173 Tidy scanner more 2021-11-03 05:03:53 -04:00
rocky
22baad273f Sync with decompyle start using types more. 2021-11-03 04:58:41 -04:00
rocky
8094f3bb12 Remove PYTHON3 2021-11-03 03:00:43 -04:00
rocky
f6f0e344d0 Python 3.6+ specialization 2021-11-03 02:23:19 -04:00
rocky
6af63deaa3 Merge branch 'master' of github.com:rocky/python-uncompyle6 2021-11-03 01:26:06 -04:00
R. Bernstein
9b5d953614 Merge pull request #364 from rocky/PYTHON3-move
use xdis.PYTHON3 not uncompyle.PYTHON3
2021-11-03 01:24:47 -04:00
R. Bernstein
33c61137d8 Merge pull request #364 from rocky/PYTHON3-move
use xdis.PYTHON3 not uncompyle.PYTHON3
2021-11-02 06:57:29 -04:00
rocky
ed34bf9d4a use xdis.PYTHON3 not uncompyle.PYTHON3 2021-11-02 06:53:11 -04:00
R. Bernstein
b4912e7b64 Merge pull request #365 from elfring/Increase_the_usage_of_augmented_assignment_statements
Convert 14 statements to the usage of augmented assignments
2021-11-02 06:51:02 -04:00
Markus Elfring
05761b0d46 Issue #363: Convert 14 statements to the usage of augmented assignments
Augmented assignment statements became available with Python 2.
https://docs.python.org/3/whatsnew/2.0.html#augmented-assignment

Thus adjust 14 source code places accordingly.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
2021-11-02 11:25:04 +01:00
rocky
7fd1cea877 Start PyPY 3.7 and 3.8 decompilation support 2021-11-02 06:05:09 -04:00
199 changed files with 9670 additions and 3814 deletions

View File

@@ -42,6 +42,8 @@ jobs:
- run:
command: | # Use pip to install dependengcies
pip install --user --upgrade setuptools
# Until the next release
pip install git+https://github.com/rocky/python-xdis#egg=xdis
pip install --user -e .
pip install --user -r requirements-dev.txt

View File

@@ -4,24 +4,46 @@ about: Tell us about uncompyle6 bugs
---
<!-- __Note:__ Bugs are not for asking questions about a problem you
<!-- __Note:__ If you are using this program to do something illegal - don't.
The issue may be flagged to make it easier for those looking for illegal activity.
Bugs are not for asking questions about a problem you
are trying to solve that involve the use of uncompyle6 along the way,
although I may be more tolerent of this if you sponsor the project.
although I may be more tolerant of this if you sponsor the project.
Bugs are also not for general or novice kind help on how to install
this Python program in your environment in the way you would like to
have it set up, or how to interpret a Python traceback e.g. that winds
up saying Python X.Y.Z is not supported.
For these kinds of things, you will save yourself time by asking
instead on forums like StackOverflow that are geared to helping people
for such general or novice kinds questions and tasks. And unless you
are a sponsor of the project, if your question seems to be of this
category, the issue may just be closed.
Also, the unless you are a sponsor of the project, it may take a
while, maybe a week or so, before the bug report is noticed, let alone
acted upon.
To set expectations, some legitimate bugs can take years
to fix, but they eventually do get fixed. Funding the project was
added to address the problem that there are lots of people seeking
help and reporting bugs, but few people who are willing or capable of
providing help or fixing bugs.
To set expectations, some legitimate bugs can take years to fix, but
they eventually do get fixed.
Finally, have you read https://github.com/rocky/python-uncompyle6/blob/master/HOW-TO-REPORT-A-BUG.md
?
Funding the project was added to partially address the problem that there are
lots of people seeking help and reporting bugs, but few people who are
willing or capable of providing help or fixing bugs.
Tasks or the kinds of things others can do, but you can't do or don't
want to do yourself are typically the kind of thing that you pay
someone to do, especially when you are the primary beneficiary of the
work, or the task is complex, long, or tedious. If your code is over
30 lines long, it fits into this category.
See also https://github.com/rocky/python-uncomp[yle6/blob/master/HOW-TO-REPORT-A-BUG.md ?
-->
<!--
Please remove any of the optional sections if they are not applicable.
Prerequisites/Caveats
@@ -34,7 +56,7 @@ Prerequisites/Caveats
contact me by email and explain who you are and the need for privacy.
But be mindful that you may be asked to sponsor the project for the
personal and private help that you are requesting.
* If the legitimacy of the activity is deemed suspicous, I may flag it as suspicious,
* If the legitimacy of the activity is deemed suspicious, I may flag it as suspicious,
making the issue even more easy to detect.
Bug reports that violate the above may be discarded.
@@ -43,7 +65,7 @@ Bug reports that violate the above may be discarded.
## Description
<!-- Add a clear and concise description of the bug. -->
<!-- Please add a clear and concise description of the bug. Try to narrow the problem down to the smallest that exhibits the bug.-->
## How to Reproduce
@@ -58,12 +80,22 @@ $ uncompyle6 <command-line-options>
$
```
Provide links to the Python bytecode. For example you can create a
Provide links to the Python bytecode. For example, you can create a
gist with the information. If you have the correct source code, you
can add that too.
-->
## Output Given
<!--
Please include not just the error message but all output leading to the message which includes echoing input and messages up to the error.
For a command-line environment include command invocation and all the output produced.
If this is too long, then try narrowing the problem to something short.
-->
## Expected behavior
<!-- Add a clear and concise description of what you expected to happen. -->
@@ -75,12 +107,20 @@ can add that too.
Please modify for your setup
- Uncompyle6 version: output from `uncompyle6 --version` or `pip show uncompyle6`
- Python version for the version of Python the byte-compiled the file: `python -c "import sys; print(sys.version)"` where `python` is the correct Cpython or Pypy binary.
- Python version for the version of Python the byte-compiled the file: `python -c "import sys; print(sys.version)"` where `python` is the correct CPython or PyPy binary.
- OS and Version: [e.g. Ubuntu bionic]
-->
## Additional Environment or Context
## Workarounds
<!-- If there is a workaround for the problem, describe that here. -->
## Priority
<!-- If this is blocking some important activity let us know what activity it blocks. -->
## Additional Context
<!-- _This section is optional._

1
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1 @@
blank_issues_enabled: False

View File

@@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [macOS]
python-version: [3.6, 3.7, 3.8]
python-version: [3.7, 3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
@@ -23,7 +23,7 @@ jobs:
run: |
python -m pip install --upgrade pip
# Until the next xdis release
pip install git+git://github.com/rocky/python-xdis.git#egg=xdis
pip install git+https://github.com/rocky/python-xdis#egg=xdis
pip install -e .
pip install -r requirements-dev.txt
- name: Test uncompyle6

View File

@@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.7, 3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
@@ -22,7 +22,7 @@ jobs:
run: |
python -m pip install --upgrade pip
# Until the next xdis release
pip install git+git://github.com/rocky/python-xdis.git#egg=xdis
pip install git+https://github.com/rocky/python-xdis#egg=xdis
pip install -e .
pip install -r requirements-dev.txt
- name: Test uncompyle6

View File

@@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [windows]
python-version: [3.6, 3.7, 3.8]
python-version: [3.7, 3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
@@ -23,7 +23,7 @@ jobs:
run: |
python -m pip install --upgrade pip
# Until the next xdis release
pip install git+git://github.com/rocky/python-xdis.git#egg=xdis
pip install git+https://github.com/rocky/python-xdis#egg=xdis
pip install -e .
pip install -r requirements-dev.txt
- name: Test uncompyle6

11
.isort.cfg Normal file
View File

@@ -0,0 +1,11 @@
[settings]
multi_line_output = 3
include_trailing_comma = True
force_grid_wrap = 0
use_parentheses = True
line_length = 88
known_crunch = cr, zz9d, zz9lib, pycrunch, silhouette
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,CRUNCH,LOCALFOLDER
default_section = THIRDPARTY
combine_as_imports = 1
profile = black

View File

@@ -1,213 +1,93 @@
This project has history of over 18 years spanning back to Python 1.5
# Introduction
There have been a number of people who have worked on this. I am awed
by the amount of work, number of people who have contributed to this,
and the cleverness in the code.
This project started around 1999 spanning back to Python 1.5
The below is an annotated history from talking to participants
involved and my reading of the code and sources cited.
In the interest of shortening what is written here, I am going to start where we left off where [decompyle 2.4's history](https://github.com/rocky/decompile-2.4/blob/master/HISTORY.md) ends.
In 1998, John Aycock first wrote a grammar parser in Python,
eventually called SPARK, that was usable inside a Python program. This
code was described in the
[7th International Python Conference](http://legacy.python.org/workshops/1998-11/proceedings/papers/aycock-little/aycock-little.html). That
paper doesn't talk about decompilation, nor did John have that in mind
at that time. It does mention that a full parser for Python (rather
than the simple languages in the paper) was being considered.
For the earlier history up to 2006 and the code up until Python 2.4, which I find interesting, look at that link.
[This](http://pages.cpsc.ucalgary.ca/~aycock/spark/content.html#contributors)
contains a of people acknowledged in developing SPARK. What's amazing
about this code is that it is reasonably fast and has survived up to
Python 3 with relatively little change. This work was done in
conjunction with his Ph.D Thesis. This was finished around 2001. In
working on his thesis, John realized SPARK could be used to deparse
Python bytecode. In the fall of 1999, he started writing the Python
program, "decompyle", to do this.
Sometime around 2014 was the dawn of ["uncompyle" and PyPI](https://pypi.python.org/pypi/uncompyle/1.1) &mdash; the era of
public version control. Dan Pascu's code although not public used [darcs](http://darcs.net/) for version control. I converted the darcs to to git and put this at [decompyle-2.4](https://github.com/rocky/decompile-2.4).
To help with control structure deparsing the instruction sequence was
augmented with pseudo instruction COME_FROM. This code introduced
another clever idea: using table-driven semantics routines, using
format specifiers.
# uncompyle, unpyc
The last mention of a release of SPARK from John is around 2002. As
released, although the Earley Algorithm parser was in good shape, this
code was woefully lacking as serious Python deparser.
In contrast to _decompyle_ that went up to Python 2.4, _uncompyle_, at least in its final versions, runs only on Python 2.7. However it accepts bytecode back to Python 2.5. Thomas Grainger is the package owner of this, although Hartmut is still listed as the author.
In the fall of 2000, Hartmut Goebel
[took over maintaining the code](https://groups.google.com/forum/#!searchin/comp.lang.python/hartmut$20goebel/comp.lang.python/35s3mp4-nuY/UZALti6ujnQJ). The
first subsequent public release announcement that I can find is
["decompyle - A byte-code-decompiler version 2.2 beta 1"](https://mail.python.org/pipermail/python-announce-list/2002-February/001272.html).
The project exists not only on [github](https://github.com/gstarnberger/uncompyle) but also on
[bitbucket](https://bitbucket.org/gstarnberger/uncompyle) and later the defunct [google
code](https://code.google.com/archive/p/unpyc/) under the name _unpyc_. The git/svn history goes back to 2009. Somewhere in there the name was changed from "decompyle" to "unpyc" by Keknehv, and then to "uncompyle" by Guenther Starnberger.
From the CHANGES file found in
[the tarball for that release](http://old-releases.ubuntu.com/ubuntu/pool/universe/d/decompyle2.2/decompyle2.2_2.2beta1.orig.tar.gz),
it appears that Hartmut did most of the work to get this code to
accept the full Python language. He added precedence to the table
specifiers, support for multiple versions of Python, the
pretty-printing of docstrings, lists, and hashes. He also wrote test and verification routines of
deparsed bytecode, and used this in an extensive set of tests that he also wrote. He says he could verify against the
entire Python library. However I have subsequently found small and relatively obscure bugs in the decompilation code.
The name Thomas Grainger isn't found in (m)any of the commits in the several years of active development. First Keknehv worked on this up to Python 2.5 or so while acceping Python bytecode back to 2.0 or so. Then "hamled" made a few commits earler on, while Eike Siewertsen made a few commits later on. But mostly "wibiti", and Guenther Starnberger got the code to where uncompyle2 was around 2012.
decompyle2.2 was packaged for Debian (sarge) by
[Ben Burton around 2002](https://packages.qa.debian.org/d/decompyle.html). As
it worked on Python 2.2 only long after Python 2.3 and 2.4 were in
widespread use, it was removed.
While John Aycock and Hartmut Goebel were well versed in compiler technology, those that have come afterwards don't seem to have been as facile in it. Furthermore, documentation or guidance on how the decompiler code worked, comparison to a conventional compiler pipeline, how to add new constructs, or debug grammars was weak. Some of the grammar tracing and error reporting was a bit weak as well.
[Crazy Compilers](http://www.crazy-compilers.com/decompyle/) offers a
byte-code decompiler service for versions of Python up to 2.6. As
someone who worked in compilers, it is tough to make a living by
working on compilers. (For example, based on
[John Aycock's recent papers](http://pages.cpsc.ucalgary.ca/~aycock/)
it doesn't look like he's done anything compiler-wise since SPARK). So
I hope people will use the crazy-compilers service. I wish them the
success that his good work deserves.
Given this, perhaps it is not surprising that subsequent changes tended to shy away from using the built-in compiler technology mechanisms and addressed problems and extensions by some other means.
Dan Pascu did a bit of work from late 2004 to early 2006 to get this
code to handle first Python 2.3 and then 2.4 bytecodes. Because of
jump optimization introduced in the CPython bytecode compiler at that
time, various JUMP instructions were classified to assist parsing For
example, due to the way that code generation and line number table
work, jump instructions to an earlier offset must be looping jumps,
such as those found in a "continue" statement; "COME FROM"
instructions were reintroduced. See
[RELEASE-2.4-CHANGELOG.txt](https://github.com/rocky/python-uncompyle6/blob/master/DECOMPYLE-2.4-CHANGELOG.txt)
for more details here. There wasn't a public release of RELEASE-2.4
and bytecodes other than Python 2.4 weren't supported. Dan says the
Python 2.3 version could verify the entire Python library. But given
subsequent bugs found like simply recognizing complex-number constants
in bytecode, decompilation wasn't perfect.
Specifically, in `uncompyle`, decompilation of python bytecode 2.5 & 2.6 is done by transforming the byte code into a pseudo-2.7 Python bytecode and is based on code from Eloi Vanderbeken. A bit of this could have been easily added by modifying grammar rules.
Next we get to ["uncompyle" and
PyPI](https://pypi.python.org/pypi/uncompyle/1.1) and the era of
public version control. (Dan's code although not public used
[darcs](http://darcs.net/) for version control.)
In contrast to _decompyle_, _uncompyle_ at least in its final versions,
runs only on Python 2.7. However it accepts bytecode back to Python
2.5. Thomas Grainger is the package owner of this, although Hartmut is
still listed as the author.
# uncompyle2, uncompyle3, uncompyle6
The project exists not only on
[github](https://github.com/gstarnberger/uncompyle) but also on
[bitbucket](https://bitbucket.org/gstarnberger/uncompyle) and later
the defunct [google
code](https://code.google.com/archive/p/unpyc/). The git/svn history
goes back to 2009. Somewhere in there the name was changed from
"decompyle" to "unpyc" by Keknehv, and then to "uncompyle" by Guenther Starnberger.
`Uncompyle6`, which I started in 2015, owes its existence to the fork of [uncompyle2](https://github.com/Mysterie/uncompyle2) by Myst herie (Mysterie) whose first commit picks up at 2012. I chose this since it seemed to have been at that time the most actively, if briefly, worked on. Also starting around 2012 is Dark Fenx's [uncompyle3](https://github.com/DarkFenX/uncompyle3) which I used for inspiration for Python3 support.
The name Thomas Grainger isn't found in (m)any of the commits in the
several years of active development. First Keknehv worked on this up
to Python 2.5 or so while acceping Python bytecode back to 2.0 or
so. Then hamled made a few commits earler on, while Eike Siewertsen
made a few commits later on. But mostly wibiti, and Guenther
Starnberger got the code to where uncompyle2 was around 2012.
While John Aycock and Hartmut Goebel were well versed in compiler
technology, those that have come afterwards don't seem to have been as
facile in it. Furthermore, documentation or guidance on how the
decompiler code worked, comparison to a conventional compiler
pipeline, how to add new constructs, or debug grammars was weak. Some
of the grammar tracing and error reporting was a bit weak as well.
Given this, perhaps it is not surprising that subsequent changes
tended to shy away from using the built-in compiler technology
mechanisms and addressed problems and extensions by some other means.
Specifically, in `uncompyle`, decompilation of python bytecode 2.5 &
2.6 is done by transforming the byte code into a pseudo-2.7 Python
bytecode and is based on code from Eloi Vanderbeken. A bit of this
could have been easily added by modifying grammar rules.
This project, `uncompyle6`, abandons that approach for various
reasons. Having a grammar per Python version is much cleaner and it
scales indefinitely. That said, we don't have entire copies of the
grammar, but work off of differences from some neighboring version.
Should there be a desire to rebase or start a new base version to work
off of, say for some future Python version, that can be done by
dumping a grammar for a specific version after it has been loaded
incrementally. You can get a full dump of the grammar by profiling the
grammar on a large body of Python source code.
Another problem with pseudo-2.7 bytecode is that that we need offsets
in fragment deparsing to be exactly the same as the bytecode; the
transformation process can remove instructions. _Adding_ instructions
with psuedo offsets is however okay.
`Uncompyle6` however owes its existence to the fork of `uncompyle2` by
Myst herie (Mysterie) whose first commit picks up at
2012. I chose this since it seemed to have been at that time the most
actively, if briefly, worked on. Also starting around 2012 is Dark
Fenx's uncompyle3 which I used for inspiration for Python3 support.
I started working on this late 2015, mostly to add fragment support.
In that, I decided to make this runnable on Python 3.2+ and Python 2.6+
while, handling Python bytecodes from Python versions 2.5+ and
3.2+. In doing so, it has been expedient to separate this into three
projects:
I started working on this late 2015, mostly to add fragment support. In that, I decided to make this runnable on Python 3.2+ and Python 2.6+ while handling Python bytecodes from Python versions 2.5+ and
3.2+. In doing so, it was expedient to separate this into three projects:
* marshaling/unmarshaling, bytecode loading and disassembly ([xdis](https://pypi.python.org/pypi/xdis)),
* parsing and tree building ([spark_parser](https://pypi.python.org/pypi/spark_parser)),
* this project - grammar and semantic actions for decompiling
([uncompyle6](https://pypi.python.org/pypi/uncompyle6)).
`uncompyle6`, abandons the idea found in some 2.7 version of `uncompyle` that support Python 2.6 and 2.5 by trying to rewite opcodes at the bytecode level.
Over the many years, code styles and Python features have
changed. However brilliant the code was and still is, it hasn't really
had a single public active maintainer. And there have been many forks
of the code. I have spent a great deal of time trying to organize and
modularize the code so that it can handle more Python versions more
gracefully (with still only moderate success).
Having a grammar per Python version is simpler to maintain, cleaner and it scales indefinitely.
That it has been in need of an overhaul has been recognized by the
Hartmut a decade an a half ago:
Over the many years, code styles and Python features have changed. However brilliant the code was and still is, it hasn't really had a single public active maintainer. And there have been many forks of the code.
That this code has been in need of an overhaul has been recognized by the Hartmut more than two decades ago.
[decompyle/uncompile__init__.py](https://github.com/gstarnberger/uncompyle/blob/master/uncompyle/__init__.py#L25-L26)
NB. This is not a masterpiece of software, but became more like a hack.
Probably a complete rewrite would be sensefull. hG/2000-12-27
This project deparses using an Earley-algorithm parse with lots of
massaging of tokens and the grammar in the scanner
phase. Earley-algorithm parsers are context free and tend to be linear
if the grammar is LR or left recursive. There is a technique for
improving LL right recursion, but our parser doesn't have that yet.
In 2021, I created three git branches in order to allow the decompiler to run on a wide variety of Python versions from 2.4 up to 3.10. (Note this doesn't mean we decompile these versions. In fact we decompile starting from Python 1.0 up to Python 3.8 and no later than that.)
Another approach to decompiling, and one that doesn't use grammars is
to do something like simulate execution symbolically and build
expression trees off of stack results. Control flow in that approach
still needs to be handled somewhat ad hoc. The two important projects
that work this way are [unpyc3](https://code.google.com/p/unpyc3/) and
most especially [pycdc](https://github.com/zrax/pycdc) The latter
project is largely by Michael Hansen and Darryl Pogue. If they
supported getting source-code fragments, did a better job in
supporting Python more fully, and had a way I could call it from
Python, I'd probably would have ditched this and used that. The code
runs blindingly fast and spans all versions of Python, although more
recently Python 3 support has been lagging. The code is impressive for
its smallness given that it covers many versions of Python. However, I
think it has reached a scalability issue, same as all the other
efforts. To handle Python versions more accurately, I think that code
base will need to have a lot more code specially which specializes for
Python versions. And then it will run into a modularity problem.
Using the separate git branches allows me to continually improve the coding style and add feature support while still supporting older Pythons. Supporting older Pythons is nice (but not strictly necessary) when you want to debug decompilation on older Pythons.
Tests for the project have been, or are being, culled from all of the
projects mentioned. Quite a few have been added to improve grammar
coverage and to address the numerous bugs that have been encountered.
I have spent a great deal of time trying to organize, modularize and even modernize the code so that it can handle more Python versions more gracefully (with still only moderate success).
If you think, as I am sure will happen in the future, "hey, I can just
write a decompiler from scratch and not have to deal with all all of
the complexity here", think again. What is likely to happen is that
you'll get at best a 90% solution working for a single Python release
that will be obsolete in about a year, and more obsolete each
subsequent year. Writing a decompiler for Python gets harder as it
Python progresses, so writing one for Python 3.7 isn't as easy as it
was for Python 2.2. That said, if you still feel you want to write a
single version decompiler, look at the test cases in this project and
talk to me. I may have some ideas.
Tests for the project have been, or are being, culled from all of the projects mentioned above or below. Quite a few have been added to improve grammar coverage and to address the numerous bugs that have been encountered.
For a little bit of the history of changes to the Earley-algorithm parser,
see the file [NEW-FEATURES.rst](https://github.com/rocky/python-spark/blob/master/NEW-FEATURES.rst) in the [python-spark github repository](https://github.com/rocky/python-spark).
# unpyc3 and pydc
NB. If you find mistakes, want corrections, or want your name added
(or removed), please contact me.
Another approach to decompiling, and one that doesn't use grammars is to do something like simulate execution symbolically and build expression trees off of stack results. Control flow in that approach
still needs to be handled somewhat ad hoc. The two important projects that work this way are [unpyc3](https://code.google.com/p/unpyc3/) and most especially [pycdc](https://github.com/zrax/pycdc) The latter
project is largely by Michael Hansen and Darryl Pogue. If they supported getting source-code fragments, did a better job in supporting Python more fully, and had a way I could call it from Python, I'd probably would have ditched this and used that. The code runs blindingly fast and spans all versions of Python, although more recently Python 3 support has been lagging. The code is impressive for its smallness given that it covers many versions of Python. However, I think it has reached a scalability issue, same as all the other efforts. To handle Python versions more accurately, I think that code base will need to have a lot more code specially which specializes for Python versions. And then it will run into a modularity problem.
# So you want to write a decompiler for Python?
If you think, as I am sure will happen in the future, "hey, I can just write a decompiler from scratch and not have to deal with all all of the complexity in uncompyle6", think again. What is likely to happen is that you'll get at best a 90% solution working for a single Python release that will be obsolete in about a year, and more obsolete each subsequent year.
Writing a decompiler for Python gets harder as it Python progresses. Writing decompiler for Python 3.7 isn't as easy as it was for Python 2.2. For one thing, now that Python has a well-established AST, that opens another interface by which code can be improved.
In Python 3.10 I am seeing (for the first time?) bytecode getting moved around so that it is no longer the case that line numbers have to be strictly increasing as bytecode offsets increase. And I am seeing dead code appear as well.
That said, if you still feel you want to write a single version decompiler, look at the test cases in this project and talk to me. I may have some ideas that I haven't made public yet. See also what I've wrtten about the on how this code works and on [decompilation in dynamic runtime languages](http://rocky.github.io/Deparsing-Paper.pdf) in general.
# Earley Algorithm Parser
This project deparses using an Earley-algorithm parse. But in order to do this accurately, the process of tokenization is a bit more involved in the scanner. We don't just disassemble bytecode and use the opcode name. That aspect hasn't changed from the very first decompilers. However understanding _what_ information needs to be made explicit and what pseudo instructions to add that accomplish this has taken some time to understand.
Earley-algorithm parsers have gotten negative press, most notably by the dragon book. Having used this a bit, I am convinced having a system that handles ambiguous grammars is the right thing to do and matches the problem well. Iin practice the speed of the parser isn't a problem when one understand what's up. And this has taken a little while to understand.
Earley-algorim parsers for context free languages or languages that are to a large extent context free and tend to be linear and the grammar stears towards left recursive rules. There is a technique for improving LL right recursion, but our parser doesn't have that yet.
The [decompiling paper](http://rocky.github.io/Deparsing-Paper.pdf) discusses these aspects in a more detail.
For a little bit of the history of changes to the Earley-algorithm parser, see the file [NEW-FEATURES.rst](https://github.com/rocky/python-spark/blob/master/NEW-FEATURES.rst) in the [python-spark github repository](https://github.com/rocky/python-spark).
NB. If you find mistakes, want corrections, or want your name added (or removed), please contact me.

View File

@@ -1,21 +1,54 @@
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
**Table of Contents**
- [The difficulty of the problem](#the-difficulty-of-the-problem)
- [Ethics](#ethics)
- [The importance of your bug report](#the-importance-of-your-bug-report)
- [The difficulty of the problem and your bug](#the-difficulty-of-the-problem-and-your-bug)
- [Is it really a bug?](#is-it-really-a-bug)
- [Do you have valid bytecode?](#do-you-have-valid-bytecode)
- [Semantic equivalence vs. exact source code](#semantic-equivalence-vs-exact-source-code)
- [What to send (minimum requirements)](#what-to-send-minimum-requirements)
- [What to send (additional helpful information)](#what-to-send-additional-helpful-information)
- [But I don't *have* the source code!](#but-i-dont-have-the-source-code)
- [But I don't *have* the source code and am incapable of figuring how how to do a hand disassembly!](#but-i-dont-have-the-source-code-and-am-incapable-of-figuring-how-how-to-do-a-hand-disassembly)
- [But I don't *have* the source code and am incapable of figuring how to do a hand disassembly!](#but-i-dont-have-the-source-code-and-am-incapable-of-figuring-how-to-do-a-hand-disassembly)
- [Narrowing the problem](#narrowing-the-problem)
- [Karma](#karma)
- [Confidentiality of Bug Reports](#confidentiality-of-bug-reports)
- [Ethics](#ethics)
<!-- markdown-toc end -->
# The difficulty of the problem
TL;DR (too long; didn't read)
* Don't do something illegal. And don't ask me to do something illegal or help you do something illegal
* We already have an infinite supply of decompilation bugs that need fixing, and an automated mechanism for finding more. Decompilation bugs get addressed by easiness to fix and by whim. If you expect yours to be fixed ahead of those, you need to justify why.
* When asking for help, you may be asked for what you've tried on your own first. There are plenty of sources of information about this code.
* If you are looking for *timely* help or support, well, that is typically known paid service. I don't really have a mechanism for that since I have a full-time job. But supporting the project is an approximation.
* Submitting a bug or issue report that is likely to get acted upon may require a bit of effort on your part to make it easy for the problem solver. If you are not willing to do that, please don't waste our time. As indicated above, supporting the project will increase the likelihood of your issue getting noticed and acted upon.
# Ethics
I do not condone using this program for unethical or illegal purposes. More detestable, at least to me, is asking for help to assist you in something that might not legitimate.
Don't use the issue tracker for such solicitations. To try to stave off illegitimate behavior, you should note that the issue tracker, the code, and bugs mentioned in that are in the open: there is no
confidentiality. You may be asked about the authorship or claimed ownership of the bytecode. If I think something is not quite right, I may label the issue questionable which may make the it easier those who are looking for illegal activity.
# The importance of your bug report
For many open-source projects bugs where the expectation is that bugs are rare, reporting bugs in a *thoughtful* way can be helpful. See also [How to Ask Questions the Smart Way](http://www.catb.org/~esr/faqs/smart-questions.html).
In this project though, most of the bug reports boil down to the something like: I have I am trying to reverse engineer some code that I am not the author/owner and that person doesn't want me to have access to. I am hitting a problem somewhere along the line which might have to do with decompilation, but it could be something else like how the bytecode was extracted, some problem in deliberately obfuscated code, or the use some kind of Python bytecode version that isn't supported by the decompiler.
While you are free to report these, unless you sponsor the project, I may close them with about the same amount of effort spent that I think was used to open the report for them. And if you spent a considerable amount of time to create the bug report but didn't follow instructions given here and in the issue template, I am sorry in advance. Just go back, read, and follow instructions.
This project already has an infinite supply of bugs that have been narrowed to the most minimal form and where I have source code to compare against. And in the unlikely event this supply runs out, I have automated means for generating *another* infinite supply.
In this project the task of justifying why addressing your bug is of use to the community, and why it should be prioritized over the others, is the bug reporter's responsibility.
While in the abstract, I have no problem answering questions about how to read a Python traceback or install Python software, or trying to understand what is going wrong in your particular setup, I am not a paid support person and there other things I'd rather be doing with my limited volunteer time. So save us both time, effort, and aggravation: use other avenues like StackOverflow. Again, justifying why you should receive unpaid help is the help requester's responsibility.
# The difficulty of the problem and your bug
This decompiler is a constant work in progress: Python keeps
changing, and so does its code generation.
@@ -27,7 +60,7 @@ But at any given time, there are a number of valid Python bytecode files that I
There are far more bug reporters than there are bug fixers.
Unless you are a sponsor of this project, it may take a while, maybe a week or so, before the bug report is noticed, let alone acted upon. Things eventually get fixed, but it may take years.
Unless you are a sponsor of this project, it may take a while, maybe a week or so, before the bug report is noticed, let alone acted upon. Things eventually get fixed, but it may take years. And if your bug hasn't been narrowed, it might happen as a result of some other bug fix.
# Is it really a bug?
@@ -35,7 +68,7 @@ Unless you are a sponsor of this project, it may take a while, maybe a week or s
## Do you have valid bytecode?
As mentioned in README.rst, this project doesn't handle obfuscated
code or release candidates. See README.rst for suggestions for how to remove some kinds of
code, release candidates, and the most recent versions of Python: version 3.9 and up. See README.rst for suggestions for how to remove some kinds of
obfuscation.
Checking if bytecode is valid is pretty simple: disassemble the code.
@@ -45,18 +78,7 @@ disassembler called `pydisasm`.
## Semantic equivalence vs. exact source code
Consider how Python compiles something like "(x*y) + 5". Early on
Python creates an "abstract syntax tree" (AST) for this. And this is
"abstract" in the sense that unimportant, redundant or unnecessary
items have been removed. Here, this means that any notion that you
wrote "x+y" in parenthesis is lost, since in this context they are
unneeded. Also lost is the fact that the multiplication didn't have
spaces around it while the addition did. It should not come as a
surprise then that the bytecode which is derived from the AST also has
no notion of such possible variation. Generally this kind of thing
isn't noticed since the Python community has laid out a very rigid set
of formatting guidelines; and it has largely beaten the community into
compliance.
Consider how Python compiles something like "(x*y) + 5". Early on Python creates an "abstract syntax tree" (AST) for this. And this is "abstract" in the sense that unimportant, redundant or unnecessary items have been removed. Here, this means that any notion that you wrote "x+y" in parenthesis is lost, since in this context they are unneeded. Also lost is the fact that the multiplication didn't have spaces around it while the addition did. It should not come as a surprise then that the bytecode which is derived from the AST also has no notion of such possible variation. Generally this kind of thing isn't noticed since the Python community has laid out a very rigid set of formatting guidelines; and it has largely beaten the community into compliance.
Almost all versions of Python can perform some sort of code
improvement that can't be undone. In earlier versions of Python it is
@@ -138,7 +160,7 @@ Also try to narrow the bug. See below.
Some kind folks also give the invocation they used and the output
which usually includes an error message produced. This is
helpful. From this, I can figure out what OS you are running this on
and what version of *uncomplye6* was used. Therefore, if you _don't_
and what version of *uncompyle6* was used. Therefore, if you _don't_
provide the input command and the output from that, please give:
* _uncompyle6_ version used
@@ -155,7 +177,7 @@ There is Python assembly code on parse errors, so simply by hand decompile that.
Well, you could learn. No one is born into this world knowing how to disassemble Python bytecode. And as Richard Feynman once said, "What one fool can learn, so can another."
If this is too difficult, or too time consuming, or not of interest to you, then you might consider [sponsoring](https://github.com/sponsors/rocky) the project. [Crazy
Compilers](http://www.crazy-compilers.com/decompyle/) offers a byte-code decompiler service for versions of Python up to 2.6. (If there are others around let me know and I'll list them here.)
Compilers](http://www.crazy-compilers.com/decompyle/) offers a byte-code decompiler service for versions of Python up to 2.6. (If there are others around let me know and I'll list them here.) Don't be surprised if I ask you to pay for work (if I think the work is ethical) when you want me to work on your problem that I think isn't of interest or benefit to anyone but yourself or a small limited number of people, or I think the need is questionable.
# Narrowing the problem
@@ -177,8 +199,11 @@ likely the problem will be fixed and fixed sooner.
# Karma
I realize that following the instructions given herein puts a bit of
burden on the bug reporter. This is justified as attempts to balance somewhat the burden and effort needed to fix the bug and the attempts to balance number of would-be bug reporters with the number of bug fixers. Better bug reporters are more likely to move
in the category of bug fixers.
burden on the bug reporter. This is justified since it attempts to balance
the burden and effort needed to fix the bug with the amount of effort to report the problem. And it attempts
to balance number of would-be bug reporters with the number of bug
fixers. Better bug reporters are more likely to move in the category
of bug fixers.
The barrier to reporting a big is pretty small: all you really need is
a github account, and the ability to type something after clicking
@@ -189,9 +214,13 @@ That said, bugs sometimes get fixed even though these instructions are not follo
I may take into consideration is the bug reporter's karma.
* Have you demonstrably contributed to open source? I may look at your github profile to see what contributions you have made, how popular those contributions are, or how popular you are.
* How appreciative are you? Have you starred this project that you are seeking help from? Have you starred _any_ github project? And the above two kind of feed into ...
* Attitude. Some people feel that they are doing me and the world a great favor by just pointing out that there is a problem whose solution would greatly benefit them. (This might account partially those that have this attitude often don't read or follow instructions such as those given here.)
* Have you demonstrably contributed to open source? I may look at your github profile to see what contributions you have made, how popular those contributions are, or how popular you are.
* How appreciative are you? Have you starred this project that you are seeking help from? Have you starred _any_ github project? And the above two kind of feed into ...
* Attitude. Some people feel that they are doing me and the world a
great favor by just pointing out that there is a problem whose
solution would greatly benefit them. (This might account partially
for the fact that those that have this attitude often don't read or
follow instructions such as those given here.)
# Confidentiality of Bug Reports
@@ -206,16 +235,4 @@ or constants in the source code.
If there is some legitimate reason to keep confidentiality, you can contact me by email to explain the extenuating circumstances. However I tend to discard without reading anonymous email.
# Ethics
I do not condone using this program for unethical or illegal purposes.
More detestable, at least to me, is asking for help to assist you in
something that might not legitimate.
Don't use the issue tracker for such solicitations. To try to stave
off illegitimate behavior, you should note that the issue tracker, the
code, and bugs mentioned in that are in the open: there is no
confidentiality. You may be asked about the authorship or claimed
ownership of the bytecode. If I think something is not quite right, I
may label the issue questionable which may make the it easier those
who are looking for illegal activity.
Private consulting available via https://calendly.com/rb3216 rates: $150 for 30 minutes; $250 for 60 minutes.

View File

@@ -11,7 +11,10 @@ RM ?= rm
LINT = flake8
#EXTRA_DIST=ipython/ipy_trepan.py trepan
PHONY=all check clean distcheck pytest check-long dist distclean lint flake8 test rmChangeLog clean_pyc
PHONY=all check check-2.7 check-3.4 \
clean distcheck pytest check-long check-short \
dist distclean lint flake8 test rmChangeLog clean_pyc \
2.6 5.0 5.3 5.6 5.8 7.2 7.3 check-short
TEST_TYPES=check-long check-short check-2.7 check-3.4
@@ -51,8 +54,12 @@ check-3.8:
7.1 pypy-3.2 2.4:
$(MAKE) -C test $@
#:PyPy pypy3-2.4.0 Python 3.6.9:
7.2:
#:PyPy versions
7.2 7.3:
$(MAKE) -C test $@
#:pyston versions
2.3:
$(MAKE) -C test $@
#: Run py.test tests

24
NEWS.md
View File

@@ -1,4 +1,26 @@
3.8.0: 2020-10-29
3.9.0: 2022-12-22
=================
* deparse generator expressions for Python 3.0 .. 3.2
* Python 3.0 list comprehension.
* Fix Issues #310, #344, #377, #391, #409, #414
* Limited support for 3.8+ f-string "=" specifier
* Correct 2.5-7 relative import formatting
* Miscellaneous bug fixing
* remove \n in lambda
* Python 2.6 gramar cleanup
* Correct some Python 2.6 chain compare decompilation
* Ensure no parenthesis subscript slices
* Correct 2.x formatting "slice2" nonterminal
* Correct 3.7 imports
* Improve "async for" parsing
* Handle BUILD_MAP opcode
* match Python AT better
* Correct 3.7 positional args
* PyPy 3.7 and PyPy 3.8 support
* Miscellaneous linting, isorting, blacking
3.8.0: 2021-10-29
=================
* Better handling of invalid bytecode magic

221
NEW_FEATURES.rst Normal file
View File

@@ -0,0 +1,221 @@
Introduction
============
The original versions of this code up until the time I started were
pretty awesome. You can get a sense of this by running it. For the
most part it was remarkably fast, and a single module with few dependencies.
Here I will largely give what are the major improvements over old code.
This also serves to outline a little bit about what is in this code.
See also `How does this code work? <https://github.com/rocky/python-uncompyle6/wiki/How-does-this-code-work%3F>`_.
Old Cool Features
==================
Before getting to the new stuff, I'll describe cool things that was there before.
I particularly liked the ability to show the assembly, grammar
reduction rules as they occurred, and the resulting parse tree. It is
neat that you could follow the process and steps that deparser takes,
and in this not only see the result how the bytecode corresponds to
the resulting source. Compare this with other Python decompilers.
And of course also neat was that this used a grammar and table-driven
approach to decompile.
Expanding decompilation to multiple Python Versions
==================================================
Aside from ``pycdc``, most of the Python decompilers handle a small
number of Python versions, if they supported more than one. And even
when more than one version is supported if you have to be running the
Python version that the bytecode was compiled for.
There main reason that you have to be running the Python bytecode
interpreter as the one you want to decompile largely stems from the
fact that Python's ``dis`` module is often what is used and that has this limitation.
``pycdc`` doesn't suffer this problem because it is written in C++,
not Python. Hartmut Goebel's code had provisions for multiple Python
versions running from an interpreter different from the one that was
running the decompiler. That however used compiled code in the process
was tied a bit to the Python C headers for a particular version.
You need to not only to account for different "marshal" and "unmarshal"
routines for the different Python versions, but also, as the Python versions
extend, you need a different code type as well.
Enter ``xdis``
--------------
To handle all of these problems, I split off the marshal loading
portion and disassembly routines into a separate module,
`xdis <https://pypi.org/project/xdis/>`_. This also allows older Pythons to have access to features
found in newer Pythons, such as parsing the bytecode, a uniform stream
of bytes, into a list of structured bytecode instructions.
Python 2.7's ``dis`` module doesn't has provide a instruction abstraction.
Therefore in ``uncompyle2`` and other earlier decompilers you see code with magic numbers like 4 in::
if end > jump_back+4 and code[end] in (JF, JA):
if code[jump_back+4] in (JA, JF):
if self.get_target(jump_back+4) == self.get_target(end):
self.fixed_jumps[pos] = jump_back+4
end = jump_back+4
elif target < pos:
self.fixed_jumps[pos] = jump_back+4
end = jump_back+4
and in other code -1 and 3 in::
if self.get_target(jmp) != start_else:
end_else = self.get_target(jmp)
if self.code[jmp] == JF:
self.fixed_jumps[jmp] = -1
self.structs.append({'type': 'except',
'start': i,
'end': jmp})
i = jmp + 3
All of that offset arithmetic is trying to find the next instruction
offset or the previous offset. Using a list of instructions you simply
take the ``offset`` field of the previous or next instruction.
The above code appears in the ``uncompyle2`` "Scanner" class in
service of trying to figure out control flow. Note also that there
isn't a single comment in there about what specifically it is trying
to do, the logic or that would lead one to be confident that this is
correct, let alone assumptions that are needed for this to be true.
While this might largely work for Python 2.7, and ``uncompyle2`` does
get control flow wrong sometimes, it is impossible to adapt code for
other versions of Python.
In addition adding an instruction structure, ``xdis`` adds various
flags and features that assist in working with instructions. In the
example above this replaces code like ``... in (JF, JA)`` which is
some sort of unconditional jump instruction.
Although not needed in the decompiler, ``xdis`` also has nicer
instruction print format. It can show you the bytes as well as the
interpreted instructions. It will interpret flag bits and packed
structures in operands so you don't have to. It can even do a limited
form of inspection at previous instructions to give a more complete
description of an operand. For example on ``LOAD_ATTR`` which loads
the attribute of a variable, often the variable name can be found as
the previous instruction. When that is the case the disassembler can
include that in the disassembly display for the ``LOAD_ATTR`` operand.
Python Grammar Isolation
------------------------
If you want to support multiple versions of Python in a manageable way
you really need to provide different grammars for the different
versions, in a grammar-based system. None of the published versions of
this decompiler did this.
If you look at the changes in this code, right now there are no
grammar changes needed between 1.0 to 1.3. (Some of this may be wrong
though since we haven't extensively tested these earliest Python versions
For Python 1.4 which is based off of the grammar for 1.5 though there
are number of changes, about 6 grammar rules. Later versions of though
we start to see larger upheaval and at certain places, especially
those where new opcodes are introduced, especially those that change
the way calls or exceptions get handled, we have major upheaval in the
grammar. It is not just that some rules get added, but we also need to
*remove* some grammar rules as well.
I have been largely managing this as incremental differences between versions.
However in the future I am leaning more towards totally separate grammars.
A well constructed grammar doesn't need to be that large.
When starting out a new version, we can just copy the grammar from the
prior version. Within a Python version though, I am breaking these
into composable pieces. In particular the grammar for handling what
can appear as the body of a lambda, is a subset of the full Python
language. The language allowed in an ``eval`` is also a subset of the
full Python language, as are what can appear in the various
compilation modes like "single" versus "exec".
Another nice natural self-contain grammar section is what can appear
in list comprehensions and generators. The bodies of these are
generally represented in a self-contained code block.
Often in decompilation you may be interested not just in decompiling
the entire code but you may be interested in only focusing on a
specific part of the code. And if there is a problem in decompiling
the entire piece of code, having these smaller breaking points can be
of assistance.
Other Modularity
----------------
Above we have mentioned the need for separate grammars or to isolate
these per versions. But there are other major pieces that make up this
decompiler. In particular there is a scanner and the source code
generation part.
Even though differences in version that occur in disassembly are
handled by ``xdis``, we still have to do conversion of that to a token
stream for parsing. So the scanners are again broken out per version
with various OO mechanisms for reusing code. The same is true for
source code generation.
Expanding decompiler availability to multiple Python Versions
--------------------------------------------------------------
Above we mention decompiling multiple versions of bytecode from a
single Python interpreter. We we talk about having the decompiler
runnable from multiple versions of Python, independent of the set of
bytecode that the decompiler supports.
There are slight advantages in having a decompiler that runs the same
version as the code you are decompiling. The most obvious one is that
it makes it easy to test to see whether the decompilation correct
because you can run the decompiled code. Python comes with a suite of
Python programs that check themselves and that aspects of Python are
implemented correctly. These also make excellent programs to check
whether a program has decompiled correctly.
Aside from this, debugging can be easier as well. To assist
understanding bytcode and single stepping it see `x-python
<https://pypi.org/project/x-python/>`_ and the debugger for it
`trepan-xpy <https://pypi.org/project/trepanxpy/>`_.
Handling Language Drift
-----------------------
Given the desirability of having this code running on logs of Python
versions, how can we get this done?
The solution used here is to have several git branches of the
code. Right now there are 3 branches. Each branch handles works across
3 or so different releases of Python. In particular one branch handles
Python 2.4 to 2.7 Another handles Python 3.3 to 3.5, and the master
branch handles 3.6 to 3.10. (Again note that the 3.9 and 3.10
decompilers do not decompile Python 3.9 or 3.10, but they do handle
bytecode for all earlier versions.)
Cool features of the Parser
===========================
* reduction rule checking
* numbering tokens
* showing a stack of completions
Cool features Semantic Analysis
===============================
* ``--tree++`` (``-T``) option
* showing precedence
* See `Adding a tree transformation phase to uncompyle6 <https://github.com/rocky/python-uncompyle6/wiki/Adding-a-tree-transformation-phase-to-uncompyle6>`_
* following AST
* Fragment deparsing

View File

@@ -2,6 +2,8 @@
|packagestatus|
.. contents::
uncompyle6
==========
@@ -75,24 +77,44 @@ the way. Very few to none of them are fixed in the other decompilers.
Requirements
------------
The code here can be run on Python versions 2.6 or later, PyPy 3-2.4
and later. Python versions 2.4-2.7 are supported in the python-2.4
branch. The bytecode files it can read have been tested on Python
The code in the git repository can be run from Python 2.4 to the
latest Python version, with the exception of Python 3.0 through
3.2. Volunteers are welcome to address these deficiencies if there a
desire to do so.
The way it does this though is by segregating consecutive Python versions into
git branches:
master
Python 3.6 and up (uses type annotations)
python-3.3-to-3.5
Python 3.3 through 3.5 (Generic Python 3)
python-2.4
Python 2.4 through 2.7 (Generic Python 2)
PyPy 3-2.4 and later works as well.
The bytecode files it can read have been tested on Python
bytecodes from versions 1.4, 2.1-2.7, and 3.0-3.8 and later PyPy
versions.
Installation
------------
This uses setup.py, so it follows the standard Python routine:
You can install from PyPI using the name ``uncompyle6``::
::
pip install uncompyle6
To install from source code, this project uses setup.py, so it follows the standard Python routine::
$ pip install -e . # set up to run from source tree
# Or if you want to install instead
or::
$ python setup.py install # may need sudo
A GNU makefile is also provided so :code:`make install` (possibly as root or
A GNU Makefile is also provided so :code:`make install` (possibly as root or
sudo) will do the steps above.
Running Tests
@@ -129,7 +151,7 @@ Verification
In older versions of Python it was possible to verify bytecode by
decompiling bytecode, and then compiling using the Python interpreter
for that bytecode version. Having done this the bytecode produced
for that bytecode version. Having done this, the bytecode produced
could be compared with the original bytecode. However as Python's code
generation got better, this no longer was feasible.
@@ -143,7 +165,7 @@ You can also cross compare the results with either another version of
`uncompyle6` since there are are sometimes regressions in decompiling
specific bytecode as the overall quality improves.
For Python 3.7 and above, the code in decompyle3_ is generally
For Python 3.7 and 3.8, the code in decompyle3_ is generally
better.
Or try specific another python decompiler like uncompyle2_, unpyc37_,
@@ -212,12 +234,14 @@ handled.
We also don't handle PJOrion_ or otherwise obfuscated code. For
PJOrion try: PJOrion Deobfuscator_ to unscramble the bytecode to get
valid bytecode before trying this tool. This program can't decompile
Microsoft Windows EXE files created by Py2EXE_, although we can
probably decompile the code after you extract the bytecode
properly. Handling pathologically long lists of expressions or
statements is slow. We don't handle Cython_ or MicroPython which don't
use bytecode.
valid bytecode before trying this tool; pydecipher_ might help with that.
This program can't decompile Microsoft Windows EXE files created by
Py2EXE_, although we can probably decompile the code after you extract
the bytecode properly. `Pydeinstaller <https://github.com/charles-dyfis-net/pydeinstaller>`_ may help with unpacking Pyinstaller bundlers.
Handling pathologically long lists of expressions or statements is
slow. We don't handle Cython_ or MicroPython which don't use bytecode.
There are numerous bugs in decompilation. And that's true for every
other CPython decompiler I have encountered, even the ones that
@@ -241,32 +265,37 @@ be solved if one were to put in the time to do so. The problem is that
there aren't that many people who have been working on bug fixing.
Some of the bugs in 3.7 and 3.8 are simply a matter of back-porting
the fixes in decompyle3.
the fixes in decompyle3. Volunteers are welcome to do so.
You may run across a bug, that you want to report. Please do so. But
be aware that it might not get my attention for a while. If you
You may run across a bug, that you want to report. Please do so after
reading `How to report a bug
<https://github.com/rocky/python-uncompyle6/blob/master/HOW-TO-REPORT-A-BUG.md>`_ and
follow the `instructions when opening an issue <https://github.com/rocky/python-uncompyle6/issues/new?assignees=&labels=&template=bug-report.md>`_.
Be aware that it might not get my attention for a while. If you
sponsor or support the project in some way, I'll prioritize your
issues above the queue of other things I might be doing instead.
See Also
--------
* https://github.com/rocky/python-decompile3 : Much smaller and more modern code, focusing on 3.7+. Changes in that will get migrated back here.
* https://github.com/rocky/python-decompile3 : Much smaller and more modern code, focusing on 3.7 and 3.8. Changes in that will get migrated back here.
* https://code.google.com/archive/p/unpyc3/ : supports Python 3.2 only. The above projects use a different decompiling technique than what is used here. Currently unmaintained.
* https://github.com/figment/unpyc3/ : fork of above, but supports Python 3.3 only. Includes some fixes like supporting function annotations. Currently unmaintained.
* https://github.com/wibiti/uncompyle2 : supports Python 2.7 only, but does that fairly well. There are situations where :code:`uncompyle6` results are incorrect while :code:`uncompyle2` results are not, but more often uncompyle6 is correct when uncompyle2 is not. Because :code:`uncompyle6` adheres to accuracy over idiomatic Python, :code:`uncompyle2` can produce more natural-looking code when it is correct. Currently :code:`uncompyle2` is lightly maintained. See its issue `tracker <https://github.com/wibiti/uncompyle2/issues>`_ for more details
* https://github.com/wibiti/uncompyle2 : supports Python 2.7 only, but does that fairly well. There are situations where :code:`uncompyle6` results are incorrect while :code:`uncompyle2` results are not, but more often uncompyle6 is correct when uncompyle2 is not. Because :code:`uncompyle6` adheres to accuracy over idiomatic Python, :code:`uncompyle2` can produce more natural-looking code when it is correct. Currently :code:`uncompyle2` is lightly maintained. See its issue `tracker <https://github.com/wibiti/uncompyle2/issues>`_ for more details.
* `How to report a bug <https://github.com/rocky/python-uncompyle6/blob/master/HOW-TO-REPORT-A-BUG.md>`_
* The HISTORY_ file.
* https://github.com/rocky/python-xdis : Cross Python version disassembler
* https://github.com/rocky/python-xasm : Cross Python version assembler
* https://github.com/rocky/python-uncompyle6/wiki : Wiki Documents which describe the code and aspects of it in more detail
* https://github.com/zrax/pycdc : The README for this C++ code says it aims to support all versions of Python. It is best for Python versions around 2.7 and 3.3 when the code was initially developed. Accuracy for current versions of Python3 and early versions of Python is lacking. Without major effort, it is unlikely it can be made to support current Python 3. See its `issue tracker <https://github.com/zrax/pycdc/issues>`_ for details. Currently lightly maintained.
* https://github.com/zrax/pycdc : The README for this C++ code says it aims to support all versions of Python. You can aim your slign shot for the moon too, but I doubt you are going to hit it. This code is best for Python versions around 2.7 and 3.3 when the code was initially developed. Accuracy for current versions of Python3 and early versions of Python is lacking. Without major effort, it is unlikely it can be made to support current Python 3. See its `issue tracker <https://github.com/zrax/pycdc/issues>`_ for details. Currently lightly maintained.
.. _Cython: https://en.wikipedia.org/wiki/Cython
.. _trepan: https://pypi.python.org/pypi/trepan2g
.. _compiler: https://pypi.python.org/pypi/spark_parser
.. _trepan: https://pypi.python.org/pypi/trepan3k
.. _compiler: https://github.com/rocky/python-uncompyle6/wiki/How-does-this-code-work%3F
.. _HISTORY: https://github.com/rocky/python-uncompyle6/blob/master/HISTORY.md
.. _report_bug: https://github.com/rocky/python-uncompyle6/blob/master/HOW-TO-REPORT-A-BUG.md
.. _debuggers: https://pypi.python.org/pypi/trepan3k
.. _remake: https://bashdb.sf.net/remake
.. _pycdc: https://github.com/zrax/pycdc
@@ -279,6 +308,7 @@ See Also
.. |packagestatus| image:: https://repology.org/badge/vertical-allrepos/python:uncompyle6.svg
:target: https://repology.org/project/python:uncompyle6/versions
.. _PJOrion: http://www.koreanrandom.com/forum/topic/15280-pjorion-%D1%80%D0%B5%D0%B4%D0%B0%D0%BA%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5-%D0%BA%D0%BE%D0%BC%D0%BF%D0%B8%D0%BB%D1%8F%D1%86%D0%B8%D1%8F-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%B8%D0%BB%D1%8F%D1%86%D0%B8%D1%8F-%D0%BE%D0%B1%D1%84
.. _pydecipher: https://github.com/mitre/pydecipher
.. _Deobfuscator: https://github.com/extremecoders-re/PjOrion-Deobfuscator
.. _Py2EXE: https://en.wikipedia.org/wiki/Py2exe
.. |Supported Python Versions| image:: https://img.shields.io/pypi/pyversions/uncompyle6.svg

View File

@@ -75,7 +75,7 @@ entry_points = {
]
}
ftp_url = None
install_requires = ["spark-parser >= 1.8.9, < 1.9.0", "xdis >= 6.0.2, < 6.1.0"]
install_requires = ["spark-parser >= 1.8.9, < 1.9.0", "xdis >= 6.0.2, < 6.2.0"]
license = "GPL3"
mailing_list = "python-debugger@googlegroups.com"

View File

@@ -0,0 +1,27 @@
#!/bin/bash
function finish {
cd $owd
}
owd=$(pwd)
trap finish EXIT
cd $(dirname ${BASH_SOURCE[0]})
if ! source ./pyenv-3.3-3.5-versions ; then
exit $?
fi
if ! source ./setup-python-3.3.sh ; then
exit $?
fi
cd ..
for version in $PYVERSIONS; do
echo --- $version ---
if ! pyenv local $version ; then
exit $?
fi
make clean && python setup.py develop
if ! make check ; then
exit $?
fi
echo === $version ===
done

View File

@@ -6,4 +6,4 @@ if [[ $0 == ${BASH_SOURCE[0]} ]] ; then
echo "This script should be *sourced* rather than run directly through bash"
exit 1
fi
export PYVERSIONS='3.1.5 3.2.6'
export PYVERSIONS='3.0.1 3.1.5 3.2.6'

View File

@@ -5,4 +5,4 @@ if [[ $0 == ${BASH_SOURCE[0]} ]] ; then
echo "This script should be *sourced* rather than run directly through bash"
exit 1
fi
export PYVERSIONS='3.6.15 3.7.12 pyston-2.3 3.8.11 3.9.7 3.10.0'
export PYVERSIONS='3.6.15 pypy3.6-7.3.1 3.7.16 pypy3.7-7.3.9 pypy3.8-7.3.10 pyston-2.3.5 3.8.16'

View File

@@ -5,4 +5,4 @@ if [[ $0 == ${BASH_SOURCE[0]} ]] ; then
echo "This script should be *sourced* rather than run directly through bash"
exit 1
fi
export PYVERSIONS='3.7.11 3.8.12 3.9.7 3.10.0'
export PYVERSIONS='3.7.13 pyston-2.3.3 3.8.13'

View File

@@ -1,5 +1,14 @@
#!/bin/bash
PYTHON_VERSION=3.7.12
PYTHON_VERSION=3.7.16
function checkout_version {
local repo=$1
version=${2:-master}
echo Checking out $version on $repo ...
(cd ../$repo && git checkout $version && pyenv local $PYTHON_VERSION) && \
git pull
return $?
}
# FIXME put some of the below in a common routine
function finish {
@@ -16,8 +25,7 @@ fi
mydir=$(dirname $bs)
fulldir=$(readlink -f $mydir)
cd $fulldir/..
(cd ../python-spark && git checkout master && pyenv local $PYTHON_VERSION) && git pull && \
(cd ../python-xdis && git checkout master && pyenv local $PYTHON_VERSION) && git pull && \
git checkout master && pyenv local $PYTHON_VERSION && git pull
(cd $fulldir/.. && checkout_version python-spark && checkout_version python-xdis &&
checkout_version python-uncompyle6)
cd $owd
rm -v */.python-version >/dev/null 2>&1 || true

View File

@@ -1,6 +1,15 @@
#!/bin/bash
PYTHON_VERSION=2.4.6
function checkout_version {
local repo=$1
version=${2:-python-2.4}
echo Checking out $version.4 on $repo ...
(cd ../$repo && git checkout $version && pyenv local $PYTHON_VERSION) && \
git pull
return $?
}
owd=$(pwd)
bs=${BASH_SOURCE[0]}
if [[ $0 == $bs ]] ; then
@@ -9,10 +18,7 @@ if [[ $0 == $bs ]] ; then
fi
mydir=$(dirname $bs)
fulldir=$(readlink -f $mydir)
cd $fulldir/..
(cd ../python-spark && git checkout python-2.4 && pyenv local $PYTHON_VERSION) && git pull && \
(cd ../python-xdis && . ./admin-tools/setup-python-2.4.sh) && \
git checkout python-2.4 && pyenv local $PYTHON_VERSION && git pull
(cd $fulldir/.. && checkout_version python-spark && checkout_version python-xdis python-2.4-to-2.7 &&
checkout_version python-uncompyle6)
cd $owd
rm -v */.python-version || true
pyenv local $PYTHON_VERSION

View File

@@ -0,0 +1,35 @@
#!/bin/bash
PYTHON_VERSION=3.0.1
pyenv local $PYTHON_VERSION
# FIXME put some of the below in a common routine
function checkout_version {
local repo=$1
version=${2:-python-3.0-to-3.2}
echo Checking out $version on $repo ...
(cd ../$repo && git checkout $version && pyenv local $PYTHON_VERSION) && \
git pull
return $?
}
function finish {
cd $owd
}
export PATH=$HOME/.pyenv/bin/pyenv:$PATH
owd=$(pwd)
bs=${BASH_SOURCE[0]}
if [[ $0 == $bs ]] ; then
echo "This script should be *sourced* rather than run directly through bash"
exit 1
fi
mydir=$(dirname $bs)
fulldir=$(readlink -f $mydir)
cd $fulldir/..
(cd $fulldir/.. && checkout_version python-spark master && checkout_version python-xdis &&
checkout_version python-uncompyle6)
cd $owd
rm -v */.python-version || true
git checkout python-3.0-to-3.2 && git pull && pyenv local $PYTHON_VERSION

View File

@@ -2,13 +2,33 @@
PYTHON_VERSION=3.3.7
pyenv local $PYTHON_VERSION
# FIXME put some of the below in a common routine
function checkout_version {
local repo=$1
version=${2:-python-3.3-to-3.5}
echo Checking out $version on $repo ...
(cd ../$repo && git checkout $version && pyenv local $PYTHON_VERSION) && \
git pull
return $?
}
function finish {
cd $owd
}
export PATH=$HOME/.pyenv/bin/pyenv:$PATH
owd=$(pwd)
bs=${BASH_SOURCE[0]}
if [[ $0 == $bs ]] ; then
echo "This script should be *sourced* rather than run directly through bash"
exit 1
fi
mydir=$(dirname $bs)
fulldir=$(readlink -f $mydir)
cd $fulldir/..
(cd ../python-xdis && ./admin-tools/setup-python-3.3.sh)
(cd $fulldir/.. && checkout_version python-spark master && checkout_version python-xdis &&
checkout_version python-uncompyle6)
cd $owd
rm -v */.python-version || true

View File

@@ -7,5 +7,5 @@ PYTHON ?= python
test check pytest:
@PYTHON_VERSION=`$(PYTHON) -V 2>&1 | cut -d ' ' -f 2 | cut -d'.' -f1,2`; \
if [[ $$PYTHON_VERSION > 3.2 ]] || [[ $$PYTHON_VERSION == 2.7 ]] || [[ $$PYTHON_VERSION == 2.6 ]]; then \
py.test; \
$(PYTHON) -m pytest .; \
fi

View File

@@ -1,10 +1,10 @@
import pytest
# uncompyle6
from uncompyle6 import PYTHON_VERSION
from xdis.version_info import PYTHON_VERSION_TRIPLE, IS_PYPY
from validate import validate_uncompyle
@pytest.mark.skipif(PYTHON_VERSION < 3.6, reason='need at least python 3.6')
@pytest.mark.skipif(PYTHON_VERSION_TRIPLE < (3, 6) or IS_PYPY, reason="need at least Python 3.6 and not PyPY")
@pytest.mark.parametrize('text', (
"{0.: 'a', -1: 'b'}", # BUILD_MAP
"{'a':'b'}", # BUILD_MAP

View File

@@ -1,6 +1,5 @@
import pytest
from uncompyle6.semantics.fragments import code_deparse as deparse, deparsed_find
from uncompyle6 import PYTHON_VERSION, PYTHON3
from uncompyle6.semantics.fragments import code_deparse as deparse
from xdis.version_info import PYTHON_VERSION_TRIPLE
def map_stmts(x, y):
x = []
@@ -30,20 +29,18 @@ def list_comp():
[y for y in range(3)]
def get_parsed_for_fn(fn):
code = fn.__code__ if PYTHON3 else fn.func_code
return deparse(code, version=PYTHON_VERSION)
code = fn.__code__
return deparse(code, version=PYTHON_VERSION_TRIPLE)
def check_expect(expect, parsed, fn_name):
debug = False
i = 2
max_expect = len(expect)
code = get_parsed_for_fn(fn_name)
for name, offset in sorted(parsed.offsets.keys()):
assert i+1 <= max_expect, (
"%s: ran out if items in testing node" % fn_name)
nodeInfo = parsed.offsets[name, offset]
node = nodeInfo.node
nodeInfo2 = deparsed_find((name, offset), parsed, code)
extractInfo = parsed.extract_node_info(node)
assert expect[i] == extractInfo.selectedLine, \
@@ -319,5 +316,3 @@ for i in range(2): ...
.
""".split("\n")
parsed = get_parsed_for_fn(for_range_stmt)
if not PYTHON3:
check_expect(expect, parsed, 'range_stmt')

View File

@@ -1,7 +1,7 @@
import os.path
import pytest
from uncompyle6.disas import disassemble_file
from uncompyle6.code_fns import disassemble_file
def get_srcdir():
filename = os.path.normcase(os.path.dirname(__file__))

View File

@@ -1,7 +1,7 @@
import re
from uncompyle6.parser import get_python_parser, python_parser
from uncompyle6.scanner import get_scanner
from xdis.version_info import PYTHON_VERSION_TRIPLE, PYTHON3, IS_PYPY
from xdis.version_info import PYTHON_VERSION_TRIPLE, IS_PYPY
def test_grammar():
@@ -34,7 +34,7 @@ def test_grammar():
expect_lhs.add("async_with_as_stmt")
expect_lhs.add("async_with_stmt")
unused_rhs = set(["list", "mkfunc", "mklambda", "unpack"])
unused_rhs = set(["list", "mkfunc", "lambda_body", "unpack"])
expect_right_recursive = set([("designList", ("store", "DUP_TOP", "designList"))])
@@ -50,35 +50,35 @@ def test_grammar():
# NOTE: this may disappear
expect_lhs.add("except_handler_else")
if PYTHON3:
expect_lhs.add("load_genexpr")
expect_lhs.add("load_genexpr")
unused_rhs = unused_rhs.union(
set(
"""
except_pop_except generator_exp
""".split()
)
unused_rhs = unused_rhs.union(
set(
"""
except_pop_except generator_exp
""".split()
)
if PYTHON_VERSION_TRIPLE >= (3, 0):
if PYTHON_VERSION_TRIPLE < (3, 7):
expect_lhs.add("annotate_arg")
expect_lhs.add("annotate_tuple")
unused_rhs.add("mkfunc_annotate")
)
if PYTHON_VERSION_TRIPLE < (3, 7):
expect_lhs.add("annotate_arg")
expect_lhs.add("annotate_tuple")
unused_rhs.add("mkfunc_annotate")
unused_rhs.add("dict_comp")
unused_rhs.add("classdefdeco1")
unused_rhs.add("tryelsestmtl")
if PYTHON_VERSION_TRIPLE >= (3, 5):
expect_right_recursive.add(
(("l_stmts", ("lastl_stmt", "come_froms", "l_stmts")))
)
pass
pass
unused_rhs.add("dict_comp")
unused_rhs.add("classdefdeco1")
unused_rhs.add("tryelsestmtl")
if PYTHON_VERSION_TRIPLE >= (3, 5):
expect_right_recursive.add(
(("l_stmts", ("lastl_stmt", "come_froms", "l_stmts")))
)
pass
else:
expect_lhs.add("kwarg")
pass
if PYTHON_VERSION_TRIPLE >= (3, 7):
expect_lhs.add("set_for")
unused_rhs.add("set_iter")
pass
pass
# FIXME
if PYTHON_VERSION_TRIPLE < (3, 8):
assert expect_lhs == set(lhs)

View File

@@ -1,19 +1,13 @@
import sys
from uncompyle6 import PYTHON3
from uncompyle6.scanner import get_scanner
from uncompyle6.semantics.consts import (
escape, NONE,
# RETURN_NONE, PASS, RETURN_LOCALS
)
if PYTHON3:
from io import StringIO
def iteritems(d):
return d.items()
else:
from StringIO import StringIO
def iteritems(d):
return d.iteritems()
from io import StringIO
def iteritems(d):
return d.items()
from uncompyle6.semantics.pysource import (SourceWalker, deparse_code2str)

View File

@@ -1,22 +1,24 @@
import pytest
from uncompyle6 import PYTHON_VERSION, code_deparse
pytestmark = pytest.mark.skip(PYTHON_VERSION < 2.7,
reason="need at least Python 2.7")
from uncompyle6 import code_deparse
from xdis.version_info import PYTHON_VERSION_TRIPLE
if PYTHON_VERSION > 2.6:
def test_single_mode():
single_expressions = (
'i = 1',
'i and (j or k)',
'i += 1',
'i = j % 4',
'i = {}',
'i = []',
'for i in range(10):\n i\n',
'for i in range(10):\n for j in range(10):\n i + j\n',
'try:\n i\nexcept Exception:\n j\nelse:\n k\n'
)
pytest.mark.skip(PYTHON_VERSION_TRIPLE < (2, 7), reason="need Python < 2.7")
for expr in single_expressions:
code = compile(expr + '\n', '<string>', 'single')
assert code_deparse(code, compile_mode='single').text == expr + '\n'
def test_single_mode():
single_expressions = (
"i = 1",
"i and (j or k)",
"i += 1",
"i = j % 4",
"i = {}",
"i = []",
"for i in range(10):\n i\n",
"for i in range(10):\n for j in range(10):\n i + j\n",
# 'try:\n i\nexcept Exception:\n j\nelse:\n k\n'
)
for expr in single_expressions:
code = compile(expr + "\n", "<string>", "single")
got = code_deparse(code, compile_mode="single").text
assert got == expr + "\n"

View File

@@ -10,7 +10,7 @@ import functools
# uncompyle6 / xdis
from uncompyle6 import code_deparse
from xdis.version_info import PYTHON_VERSION_TRIPLE, PYTHON3, IS_PYPY
from xdis.version_info import PYTHON_VERSION_TRIPLE, IS_PYPY
# TODO : I think we can get xdis to support the dis api (python 3 version) by doing something like this there
from xdis import Bytecode, get_opcode
@@ -19,12 +19,6 @@ opc = get_opcode(PYTHON_VERSION_TRIPLE, IS_PYPY)
Bytecode = functools.partial(Bytecode, opc=opc)
import six
if PYTHON3:
from io import StringIO
else:
from StringIO import StringIO
def _dis_to_text(co):
return Bytecode(co).dis()

View File

@@ -2,3 +2,8 @@
hypothesis==2.0.0
pytest
-e .
Click~=7.0
xdis>=6.0.4
configobj~=5.0.6
setuptools~=65.5.1

View File

@@ -1,11 +1,12 @@
#!/usr/bin/env python
import setuptools
import sys
"""Setup script for the 'uncompyle6' distribution."""
SYS_VERSION = sys.version_info[0:2]
if not ((2, 4) <= SYS_VERSION < (3, 11)):
mess = "Python Release 2.6 .. 3.10 are supported in this code branch."
if not ((2, 4) <= SYS_VERSION < (3, 12)):
mess = "Python Release 2.6 .. 3.11 are supported in this code branch."
if (2, 4) <= SYS_VERSION <= (2, 7):
mess += (
"\nFor your Python, version %s, use the python-2.4 code/branch."
@@ -39,9 +40,7 @@ from __pkginfo__ import (
zip_safe,
)
from setuptools import setup, find_packages
setup(
setuptools.setup(
author=author,
author_email=author_email,
classifiers=classifiers,
@@ -52,7 +51,7 @@ setup(
long_description=long_description,
long_description_content_type="text/x-rst",
name=modname,
packages=find_packages(),
packages=setuptools.find_packages(),
py_modules=py_modules,
test_suite="nose.collector",
url=web,

View File

@@ -72,6 +72,9 @@ check-3.7: check-bytecode
$(PYTHON) test_pythonlib.py --bytecode-3.7-run --verify-run
$(PYTHON) test_pythonlib.py --bytecode-3.7 --syntax-verify $(COMPILE)
check-pypy37: check-bytecode
$(PYTHON) test_pythonlib.py --bytecode-pypy37 --verify-run
#: Run working tests from Python 3.8
check-3.8: check-bytecode
$(PYTHON) test_pythonlib.py --bytecode-3.8-run --verify-run
@@ -84,8 +87,8 @@ check-3.10: check-bytecode
@echo "Note that we do not support decompiling Python 3.10 bytecode - no 3.10 tests run"
# FIXME
#: this is called when running under pypy3.5-5.8.0, pypy2-5.6.0, or pypy3.6-7.3.0
5.8 5.6:
#: this is called when running under pypy3.5-5.8.0, pypy2-5.6.0, pypy3.6-7.3.0 or pypy3.8-7.3.7
5.8 5.6 7.3:
#: Check deparsing only, but from a different Python version
check-disasm:
@@ -179,12 +182,24 @@ check-bytecode-2.3:
#: Check deparsing Python 2.4
check-bytecode-2.4:
$(PYTHON) test_pythonlib.py --bytecode-2.4-run --verify-run
$(PYTHON) test_pythonlib.py --bytecode-2.4
#: Check deparsing Python 2.5
check-bytecode-2.5:
$(PYTHON) test_pythonlib.py --bytecode-2.5-run --verify-run
$(PYTHON) test_pythonlib.py --bytecode-2.5
#: Check deparsing Python 2.6
check-bytecode-2.6:
$(PYTHON) test_pythonlib.py --bytecode-2.6-run --verify-run
$(PYTHON) test_pythonlib.py --bytecode-2.6 --syntax-verify
#: Check deparsing Python 2.7
check-bytecode-2.7:
$(PYTHON) test_pythonlib.py --bytecode-2.7-run --verify-run
$(PYTHON) test_pythonlib.py --bytecode-2.7 --syntax-verify
#: Get grammar coverage for Python 2.4
grammar-coverage-2.4:
-rm $(COVER_DIR)/spark-grammar-24.cover
@@ -257,16 +272,6 @@ grammar-coverage-3.7:
rm $(COVER_DIR)/spark-grammar-3.7.cover || /bin/true
SPARK_PARSER_COVERAGE=$(COVER_DIR)/spark-grammar-3.7.cover $(PYTHON) test_pyenvlib.py --3.7.3 --max=500
#: Check deparsing Python 2.6
check-bytecode-2.6:
$(PYTHON) test_pythonlib.py --bytecode-2.6-run --verify-run
$(PYTHON) test_pythonlib.py --bytecode-2.6 --syntax-verify
#: Check deparsing Python 2.7
check-bytecode-2.7:
$(PYTHON) test_pythonlib.py --bytecode-2.7-run --verify-run
$(PYTHON) test_pythonlib.py --bytecode-2.7 --syntax-verify
#: Check deparsing Python 3.0
check-bytecode-3.0:
$(PYTHON) test_pythonlib.py --bytecode-3.0-run --verify-run
@@ -353,11 +358,16 @@ check-bytecode-pypy3.6: 7.1
#: PyPy 5.0.x with Python 3.6.9
check-bytecode-pypy3.6: 7.2 7.3
7.3 7.2:
7.2:
$(PYTHON) test_pythonlib.py --bytecode-pypy3.6-run --verify-run
$(PYTHON) test_pythonlib.py --bytecode-pypy3.6 --verify
7.3:
$(PYTHON) test_pythonlib.py --bytecode-pypy3.7 --verify-run
# Pyston 2.3
2.3: check-3.8
clean: clean-py-dis clean-dis clean-unverified

View File

@@ -1,13 +1,19 @@
#!/usr/bin/env python
""" Trivial helper program to bytecompile and run an uncompile
""" Trivial helper program to byte compile and uncompile the bytecode file.
"""
import os, sys, py_compile
from xdis.version_info import version_tuple_to_str, PYTHON_VERSION_TRIPLE
assert (2 <= len(sys.argv) <= 4)
if len(sys.argv) < 2:
print("Usage: add-test.py [--run] *python-source*... [optimize-level]")
sys.exit(1)
assert 2 <= len(sys.argv) <= 4
version = sys.version[0:3]
vers = sys.version_info[:2]
if sys.argv[1] in ("--run", "-r"):
suffix = "_run"
assert len(sys.argv) >= 3
py_source = sys.argv[2:]
i = 2
else:
@@ -16,21 +22,28 @@ else:
i = 1
try:
optimize = int(sys.argv[-1])
assert sys.argv >= i + 2
py_source = sys.argv[i:-1]
i = 2
except:
optimize = 2
for path in py_source:
short = os.path.basename(path)
if short.endswith(".py"):
short = short[: -len(".py")]
if hasattr(sys, "pypy_version_info"):
cfile = "bytecode_pypy%s%s/%s" % (version, suffix, short) + "c"
version = version_tuple_to_str(end=2, delimiter="")
bytecode = "bytecode_pypy%s%s/%spy%s.pyc" % (version, suffix, short, version)
else:
cfile = "bytecode_%s%s/%s" % (version, suffix, short) + "c"
print("byte-compiling %s to %s" % (path, cfile))
optimize = optimize
if vers > (3, 1):
py_compile.compile(path, cfile, optimize=optimize)
version = version_tuple_to_str(end=2)
bytecode = "bytecode_%s%s/%s.pyc" % (version, suffix, short)
print("byte-compiling %s to %s" % (path, bytecode))
if PYTHON_VERSION_TRIPLE >= (3, 2):
py_compile.compile(path, bytecode, optimize=optimize)
else:
py_compile.compile(path, cfile)
if vers >= (2, 6):
os.system("../bin/uncompyle6 -a -T %s" % cfile)
py_compile.compile(path, bytecode)
if PYTHON_VERSION_TRIPLE >= (2, 6):
os.system("../bin/uncompyle6 -a -t %s" % bytecode)

Binary file not shown.

BIN
test/bytecode_1.0/stat.pyc Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -5,7 +5,7 @@
# fully handle Python 3.5's jump optimization
# So in 3.5, for now, we allow:
#
# return_stmt ::= ret_expr RETURN_END_IF
# return_stmt ::= return_expr RETURN_END_IF
# and you see that in the grammar rules for below.
# For other pythons the RETURN_END_IF may be a

View File

@@ -1,9 +1,9 @@
# Tests:
# ret_expr_or_cond ::= ret_expr
# if_exp_ret ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF ret_expr_or_cond
# ret_expr_or_cond ::= if_exp_ret
# ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM
# return_expr_or_cond ::= return_expr
# if_exp_ret ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF return_expr_or_cond
# return_expr_or_cond ::= if_exp_ret
# ret_or ::= expr JUMP_IF_TRUE_OR_POP return_expr_or_cond COME_FROM
# See https://github.com/rocky/python-uncompyle6/issues/5

View File

@@ -0,0 +1,8 @@
from test_support import *
print '4. Built-in functions'
print 'test_b1'
unload('test_b1')
import test_b1
print 'test_b2'
unload('test_b2')
import test_b2

View File

@@ -0,0 +1,18 @@
"""This program is self-checking!"""
# Python 2.4 - 2.7 bug in transforming "else if" to "elif" in Python 2.4 .. 2.7
# From Issue #377
# RUNNABLE!
def loop_continue_dead_code(slots):
for name in slots:
if name:
pass
else:
continue
# The below is dead code
if x:
y()
else:
z()
loop_continue_dead_code([None, 1])

View File

@@ -0,0 +1,7 @@
# Bug was erroneously putting quotes around Exception on decompilatoin
# RUNNABLE!
"""This program is self-checking!"""
z = ["y", Exception]
assert z[0] == "y"
assert isinstance(z[1], Exception)

View File

@@ -0,0 +1,41 @@
# Issue #413 on 2.7
# Bug in handling CONTINUE in else block of if-then-else in a for loop
# Bug was "if" and "else" jump back to loop getting detected.
# RUNNABLE!
"""This program is self-checking!"""
def test1(a, r = []):
for b in a:
if b:
r.append(3)
else:
r.append(5)
continue
if r == []:
pass
return r
def test2(a, r = None):
for b in a:
if b:
#pass # No payload
continue
raise AssertionError("CONTINUE not followed")
else:
continue
raise AssertionError("CONTINUE not followed")
if b:
r = b
raise AssertionError("CONTINUE not followed")
return r
assert test1([], []) == [], "For loop not taken"
assert test1([False], []) == [5], "if 'else' should have been taken"
assert test1([True], []) == [3], "if 'then' should have been taken"
assert test1([True, True], []) == [3, 3], "if should have been taken"
assert test1([True, False], []) == [3, 5], "if and then 'else' should have been taken"
assert test1([False, True], []) == [5, 3], "if else and then 'then' should have been taken"
assert test1([False, False], []) == [5, 5], "if else should have been taken twice"
assert test1([True, True], []) == [3, 3], "if 'then' should have been taken twice"
assert test2([True]) is None, "Incorrect flow"
assert test2([False]) is None, "Incorrect flow"

View File

@@ -2,6 +2,8 @@
from math import atan2
# RUNNABLE!
"""This program is self-checking!"""
def assertCloseAbs(x, y, eps=1e-09):
"""Return true iff floats x and y "are close\""""
if abs(x) > abs(y):
@@ -32,7 +34,7 @@ def check_div(x, y):
assertClose(q, x)
def test_truediv():
simple_real = [float(i) for i in range(-5, 6)]
simple_real = [float(i) for i in range(-3, 3)]
simple_complex = [complex(x, y) for x in simple_real for y in simple_real]
for x in simple_complex:
for y in simple_complex:
@@ -43,7 +45,7 @@ def test_plus_minus_0j():
assert -0-0j == -0j == complex(0.0, 0.0)
z1, z2 = (0j, -0j)
assert atan2(z1.imag, -1.0) == atan2(0.0, -1.0)
# assert atan2(z2.imag, -1.0), atan2(-0.0, -1.0)
assert atan2(z2.imag, -1.0), atan2(-0.0, -1.0)
# Check that we can handle -inf, and inf as a complex numbers.
# And put it in a tuple and a list to make it harder.

View File

@@ -0,0 +1,18 @@
# Related to #426
# This file is RUNNABLE!
"""This program is self-checking!"""
a = 5
class MakeClosureTest():
# This function uses MAKE_CLOSURE with annotation args
def __init__(self, dev: str, b: bool):
super().__init__()
self.dev = dev
self.b = b
self.a = a
x = MakeClosureTest("dev", True)
assert x.dev == "dev"
assert x.b == True
assert x.a == 5

View File

@@ -1,5 +1,5 @@
# Python 3.6, uses rule:
# genexpr ::= load_closure load_genexpr LOAD_CONST
# MAKE_FUNCTION_8 expr GET_ITER CALL_FUNCTION_1
# MAKE_FUNCTION_CLOSURE expr GET_ITER CALL_FUNCTION_1
def __sub__(self, other): # SList()-other
return self.__class__(i for i in self if i not in other)

View File

@@ -0,0 +1,48 @@
# These are from 3.6 test_coroutines.py
async def run_gen(f):
return (10 async for i in f)
async def run_list(f):
return [i async for i in f()]
# async def run_dict():
# return {i + 1 async for i in [10, 20]}
async def iterate(gen):
res = []
async for i in gen:
res.append(i)
return res
def test_comp_5(f):
# async def f(it):
# for i in it:
# yield i
async def run_list():
return [i
for
pair in
([10, 20])
async for i
in f
]
async def test2(x, buffer, f):
with x:
async for i in f:
if i:
break
else:
buffer()
buffer()
async def test3(x, buffer, f):
with x:
async for i in f:
if i:
continue
buffer()
else:
buffer.append()
buffer()

View File

@@ -1,11 +1,11 @@
# From Python 3.6 hmac.py
# needed to change mklambda rule
# needed to change lambda_body rule
def __init__(self, msg = None, digestmod = None):
self.digest_cons = lambda d='': digestmod.new(d)
# From Python 3.6 functools.py
# Bug was handling lambda for MAKE_FUNCTION_8 (closure)
# vs to MAKE_FUNCTION_9 (pos_args + closure)
# Bug was handling lambda for MAKE_FUNCTION_CLOSURE (closure)
# vs to MAKE_FUNCTION_CLOSURE_POS (pos_args + closure)
def bug():
def register(cls, func=None):
return lambda f: register(cls, f)

View File

@@ -2,13 +2,23 @@
# String interpolation tests
# RUNNABLE!
var1 = 'x'
var2 = 'y'
abc = 'def'
assert (f"interpolate {var1} strings {var2!r} {var2!s} 'py36" ==
"interpolate x strings 'y' y 'py36")
assert 'def0' == f'{abc}0'
assert 'defdef' == f'{abc}{abc!s}'
"""This program is self-checking!"""
var1 = "x"
var2 = "y"
abc = "def"
assert (
f"interpolate {var1} strings {var2!r} {var2!s} 'py36"
== "interpolate x strings 'y' y 'py36"
)
assert "def0" == f"{abc}0"
assert "defdef" == f"{abc}{abc!s}"
# From 3.8 test/test_string.py
# We had the precedence of yield vs. lambda incorrect.
def fn(x):
yield f"x:{yield (lambda i: x * i)}"
# From 3.6 functools.py
# Bug was handling format operator strings.
@@ -21,51 +31,51 @@ assert y == "functools.1=['2'](2)"
# From 3.6 http/client.py
# Bug is in handling X
chunk = ['a', 'b', 'c']
chunk2 = 'd'
chunk = f'{len(chunk):X}' + chunk2
assert chunk == '3d'
chunk = ["a", "b", "c"]
chunk2 = "d"
chunk = f"{len(chunk):X}" + chunk2
assert chunk == "3d"
chunk = b'abc'
chunk2 = 'd'
chunk = f'{len(chunk):X}\r\n'.encode('ascii') + chunk \
+ b'\r\n'
assert chunk == b'3\r\nabc\r\n'
chunk = b"abc"
chunk2 = "d"
chunk = f"{len(chunk):X}\r\n".encode("ascii") + chunk + b"\r\n"
assert chunk == b"3\r\nabc\r\n"
# From 3.6.8 idlelib/pyshell.py
# Bug was handling '''
import os
filename = '.'
source = 'foo'
source = (f"__file__ = r'''{os.path.abspath(filename)}'''\n"
+ source + "\ndel __file__")
filename = "."
source = "foo"
source = f"__file__ = r'''{os.path.abspath(filename)}'''\n" + source + "\ndel __file__"
# Note how { and } are *not* escaped here
f = 'one'
name = 'two'
assert(f"{f}{'{{name}}'} {f}{'{name}'}") == 'one{{name}} one{name}'
f = "one"
name = "two"
assert (f"{f}{'{{name}}'} {f}{'{name}'}") == "one{{name}} one{name}"
# From 3.7.3 dataclasses.py
log_rounds = 5
assert "05$" == f'{log_rounds:02d}$'
log_rounds = 5
assert "05$" == f"{log_rounds:02d}$"
def testit(a, b, l):
# print(l)
return l
def testit(a, b, ll):
# print(ll)
return ll
# The call below shows the need for BUILD_STRING to count expr arguments.
# Also note that we use {{ }} to escape braces in contrast to the example
# above.
def _repr_fn(fields):
return testit('__repr__',
('self',),
['return xx + f"(' +
', '.join([f"{f}={{self.{f}!r}}"
for f in fields]) +
')"'])
return testit(
"__repr__",
("self",),
['return xx + f"(' + ", ".join([f"{f}={{self.{f}!r}}" for f in fields]) + ')"'],
)
fields = ['a', 'b', 'c']
fields = ["a", "b", "c"]
assert _repr_fn(fields) == ['return xx + f"(a={self.a!r}, b={self.b!r}, c={self.c!r})"']
@@ -85,28 +95,31 @@ else:
assert False, "f'{lambda x:x}' should be a syntax error"
(x, y, width) = ("foo", 2, 10)
assert f'x={x*y:{width}}' == 'x=foofoo '
assert f"x={x*y:{width}}" == "x=foofoo "
# Why the fact that the distinction of docstring versus stmt is a
# string expression is important academic, but we will decompile an
# equivalent thing. For compatiblity with older Python we'll use "%"
# instead of a format string
def f():
f'''Not a docstring'''
f"""Not a docstring""" # noqa
def g():
'''Not a docstring''' \
f''
"""Not a docstring""" f"" # noqa
assert f.__doc__ is None
assert g.__doc__ is None
import decimal
width, precision, value = (10, 4, decimal.Decimal('12.34567'))
width, precision, value = (10, 4, decimal.Decimal("12.34567"))
# Make sure we don't have additional f'..' inside the format strings below.
assert f'result: {value:{width}.{precision}}' == 'result: 12.35'
assert f'result: {value:{width:0}.{precision:1}}' == 'result: 12.35'
assert f'{2}\t' == '2\t'
assert f"result: {value:{width}.{precision}}" == "result: 12.35"
assert f"result: {value:{width:0}.{precision:1}}" == "result: 12.35"
assert f"{2}\t" == "2\t"
# But below we *do* need the additional f".."
assert f'{f"{0}"*3}' == "000"
@@ -115,4 +128,18 @@ assert f'{f"{0}"*3}' == "000"
# ^
# The former, {{ confuses the format strings so dictionary/set comprehensions
# don't work.
assert f'expr={ {x: y for x, y in [(1, 2), ]}}' == 'expr={1: 2}'
assert f"expr={ {x: y for x, y in [(1, 2), ]}}" == "expr={1: 2}"
class Line:
def __init__(self, x, y):
self.x = x
self.y = y
# From 3.7 test_typing.py
def __str__(self):
return f"{self.x} -> {self.y}"
line = Line(1, 2)
assert str(line) == "1 -> 2"

View File

@@ -0,0 +1,272 @@
# This is RUNNABLE!
"""This program is self-checking!"""
# Bug was handling if which has EXTENDED_ARG
# See https://github.com/rocky/python-uncompyle6/pull/406
aa = 0
ab = 0
ac = 0
ad = 0
ae = 0
af = 0
ag = 0
ah = 0
ai = 0
aj = 0
ak = 0
al = 0
am = 0
an = 0
ao = 0
ap = 0
aq = 0
ar = 0
at = 0
au = 0
av = 0
aw = 0
ax = 0
ay = 0
az = 0
ba = 0
bb = 0
bc = 0
bd = 0
be = 0
bf = 0
bg = 0
bh = 0
bi = 0
bj = 0
bk = 0
bl = 0
bm = 0
bn = 0
bo = 0
bp = 0
bq = 0
br = 0
bs = 0
bt = 0
bu = 0
bv = 0
bw = 0
bx = 0
by = 0
bz = 0
ca = 0
cb = 0
cc = 0
cd = 0
ce = 0
cf = 0
cg = 0
ch = 0
ci = 0
cj = 0
ck = 0
cl = 0
cm = 0
cn = 0
co = 0
cp = 0
cq = 0
cr = 0
cs = 0
ct = 0
cu = 0
cv = 0
cw = 0
cx = 0
cy = 0
cz = 0
da = 0
db = 0
dc = 0
dd = 0
de = 0
df = 0
dg = 0
dh = 0
di = 0
dj = 0
dk = 0
dl = 0
dm = 0
dn = 0
do = 0
dp = 0
dq = 0
dr = 0
ds = 0
dt = 0
du = 0
dv = 0
dw = 0
dx = 0
dy = 0
dz = 0
ea = 0
eb = 0
ec = 0
ed = 0
ee = 0
ef = 0
eg = 0
eh = 0
ei = 0
ej = 0
ek = 0
el = 0
em = 0
en = 0
eo = 0
ep = 0
eq = 0
er = 0
es = 0
et = 0
eu = 0
ev = 0
ew = 0
ex = 0
ey = 0
ez = 0
fa = 0
fb = 0
fc = 0
fd = 0
fe = 0
ff = 0
fg = 0
fh = 0
fi = 0
fj = 0
fk = 0
fl = 0
fm = 0
fn = 0
fo = 0
fp = 0
fq = 0
fr = 0
fs = 0
ft = 0
fu = 0
fv = 0
fw = 0
fx = 0
fy = 0
fz = 0
ga = 0
gb = 0
gc = 0
gd = 0
ge = 0
gf = 0
gg = 0
gh = 0
gi = 0
gj = 0
gk = 0
gl = 0
gm = 0
gn = 0
go = 0
gp = 0
gq = 0
gr = 0
gs = 0
gt = 0
gu = 0
gv = 0
gw = 0
gx = 0
gy = 0
gz = 0
ha = 0
hb = 0
hc = 0
hd = 0
he = 0
hf = 0
hg = 0
hh = 0
hi = 0
hj = 0
hk = 0
hl = 0
hm = 0
hn = 0
ho = 0
hp = 0
hq = 0
hr = 0
hs = 0
ht = 0
hu = 0
hv = 0
hw = 0
hx = 0
hy = 0
hz = 0
ia = 0
ib = 0
ic = 0
id = 0
ie = 0
ig = 0
ih = 0
ii = 0
ij = 0
ik = 0
il = 0
im = 0
io = 0
ip = 0
iq = 0
ir = 0
it = 0
iu = 0
iv = 0
iw = 0
ix = 0
iy = 0
iz = 0
ja = 0
jb = 0
jc = 0
jd = 0
je = 0
jf = 0
jg = 0
jh = 0
ji = 0
jj = 0
jk = 0
jl = 0
jm = 0
jn = 0
jo = 0
jp = 0
jq = 0
jr = 0
js = 0
jt = 0
ju = 0
jv = 0
jw = 0
jx = 0
jy = 0
jz = 0
ka = 0
kb = 0
kc = 0
var = True
if var:
aa = 1
else:
aa = 2
assert aa == 1

View File

@@ -0,0 +1,12 @@
# Issue 104
# Python 3.8 reverses the order or keys and values in
# dictionary comprehensions from the order in all previous Pythons.
# Also we were looking in the wrong place for the collection of the
# dictionary comprehension
# RUNNABLE!
"""This program is self-checking!"""
x = [(0, [1]), (2, [3])]
for i in range(0, 1):
y = {key: val[i - 1] for (key, val) in x}
assert y == {0: 1, 2: 3}

View File

@@ -0,0 +1,6 @@
# The 3.8 bugs were in detecting
# 1) while True: pass
# 2) confusing the "if" ending in a loop jump with a "while"
if __name__:
while True:
pass

View File

@@ -0,0 +1,32 @@
# Tests new "debug" format new in 3.8.
# Much of this is adapted from 3.8 test/test_fstring.py
# RUNNABLE!
"""This program is self-checking!"""
# fmt: off
# We want to use "=" and ":=" *without* the surrounding space to test format spec and "=" detection
f'{f"{3.1415=:.1f}":*^20}' == '*****3.1415=3.1*****'
y = 2
def f(x, width):
return f'x={x*y:{width}}'
assert f('foo', 10) == 'x=foofoo '
x = 'bar'
assert f(10, 10), 'x= 20'
x = 'A string'
f"x={x!r}" == 'x=' + repr(x)
pi = 'π'
assert f'alpha α {pi=} ω omega', "alpha α pi='π' ω omega"
x = 20
# This isn't an assignment expression, it's 'x', with a format
# spec of '=10'.
assert f'{x:=10}' == ' 20'
assert f'{(x:=10)}' == '10'
assert x == 10

View File

@@ -0,0 +1,14 @@
# From 3.8 test_named_expressions.py
# Bug was not putting parenthesis around := below
# RUNNABLE!
"""This program is self-checking!"""
(a := 10)
assert a == 10
# Bug was not putting all of the levels of parentheses := below
(z := (y := (x := 0)))
assert x == 0
assert y == 0
assert z == 0

View File

@@ -0,0 +1,62 @@
# From uncompyle issue #295 on 3.8
# In 3.8 BREAK_LOOP and CONTINUE_LOOP no longer exist.
# The bug is that the "break" is turned into:
# POP_BLOCK
# JUMP_ABSOLUTE
while True:
try:
x = 1
break
except Exception:
pass
while True:
try:
x -= 1
except Exception:
break
# Issue #25 https://github.com/rocky/python-decompile3/issues/25
# Same as above using "for".
for i in range(5):
try:
x = 1
break
except Exception:
if i == 4:
raise
# From 3.8.1 _osx_support.py
# Bug was handling a "break" inside a "try".
# In 3.8 POP_EXCEPT is moved before "JUMP_ABSOLUTE" of
# the break.
# FIXME:
# def compiler_fixup(compiler_so, cc_args, index):
# if index:
# while True:
# try:
# index = 1
# except:
# index = 2
# break
# Bug was returning an IfExp inside "with":
# the return value is mixed in with the "with"
# code finalization.
# FIXME:
# def _read_output(x, a):
# with x as fp:
# return fp if a else None
# In 3.8 the CONTINUE_LOOP disappears,
# and this makes it harder to detect continue
# inside a loop with a continue in the except clause.
def connect_ws_with_retry(f1, f2):
while True:
try:
f1()
except Exception:
f2()
continue

View File

@@ -0,0 +1,21 @@
"""This program is self-checking!"""
class C:
def sort(self, l, reverse, key_fn):
# PyPy example of CALL_METHOD_KW 2
# 2 keyword arguments and no positional arguments
return l.sort(reverse=reverse, key=key_fn)
def lcase(s):
return s.lower()
x = C()
l = ["xyz", "ABC"]
# An PyPy example of CALL_METHOD_KW 3
# 2 keyword arguments and one positional argument
x.sort(l, reverse=False, key_fn=lcase)
assert l == ["ABC", "xyz"]

View File

@@ -1,3 +0,0 @@
# Long lists pose a slowdown in uncompiling.
x = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
print(x)

View File

@@ -0,0 +1,727 @@
# Long lists pose a slowdown in uncompiling.
"This program is self-checking!"
# Try an empty list to check that long-matching detection doesn't mess that up.
# In theory this should work even though we put cap on short lists which
# is checked below.
x = []
assert len(x) == 0 and isinstance(x, list)
# Try an short list to check that long-matching detection doesn't mess that up.
# This is a more general situation of the above.
x = [1, 1, 1]
# Until we have better "and" rules (which we have
# around, but not in decompyle3 or uncompyle6 yet)
# avoid 3-term "and"s
assert len(x) == 3
assert isinstance(x, list) and all(x)
# fmt: off
# Try a long list. This should not be slow
# as it has been in the past.
x = [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
]
assert all(x)
assert len(x) == 300 and isinstance(x, list)
# Try a long set. This should not be slow
# as it has been in the past.
x = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
}
assert x == {1} and isinstance(x, set)
# Try using variables rather than constants
a = 1
# First, a list
x = [
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
]
assert all(x)
assert len(x) == 300 and isinstance(x, list)
# Next, a set
x = {
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
}
assert x == {1} and isinstance(x, set)
# Check some dictionary keys.
# Ensure that in dictionary we produce quoted strings
x = {
"b": 1,
"c": 2,
"e": 3,
"g": 6,
"h": 7,
"j": 9,
"k": 11,
"return": 12,
}
# We need sorted here and below, because x.keys() in 2.7 comes out in the reverse order.
# Go figure.
assert sorted(x.keys()) == ["b", "c", "e", "g", "h", "j", "k", "return"]
# Ensure that in dictionary we produce integers, not strings
x = {1: 2, 3: 4}
assert tuple(x.keys()) == (1, 3)
# Try a long dictionary.
# This should not be slow as it has been in the past
values = {
"value1": x, # Note this is LOAD_NAME
"value2": 2 + 1, # Constant should be folded into "LOAD_CONST"
"value3": 3 + 1,
"value4": 4 + 1,
"value5": 5 + 1,
"value6": 6 + 1,
"value7": 7 + 1,
"value8": 8 + 1,
"value9": 9 + 1,
"value10": 10 + 1,
"value11": 11 + 1,
"value12": 12 + 1,
"value13": 13 + 1,
"value14": 14 + 1,
"value15": 15 + 1,
"value16": 16 + 1,
"value17": 17 + 1,
"value18": 18 + 1,
"value19": 19 + 1,
"value20": 20 + 1,
"value21": 21 + 1,
"value22": 22 + 1,
"value23": 23 + 1,
"value24": 24 + 1,
"value25": 25 + 1,
"value26": 26 + 1,
"value27": 27 + 1,
"value28": 28 + 1,
"value29": 29 + 1,
"value30": 30 + 1,
"value31": 31 + 1,
"value32": 32 + 1,
"value33": 33 + 1,
"value34": 34 + 1,
"value35": 35 + 1,
"value36": 36 + 1,
"value37": 37 + 1,
"value38": 38 + 1,
"value39": 39 + 1,
"value40": 40 + 1,
"value41": 41 + 1,
"value42": 42 + 1,
"value43": 43 + 1,
"value44": 44 + 1,
"value45": 45 + 1,
"value46": 46 + 1,
"value47": 47 + 1,
"value48": 48 + 1,
"value49": 49 + 1,
"value50": 50 + 1,
"value51": 51 + 1,
"value52": 52 + 1,
"value53": 53 + 1,
"value54": 54 + 1,
"value55": 55 + 1,
"value56": 56 + 1,
"value57": 57 + 1,
"value58": 58 + 1,
"value59": 59 + 1,
"value60": 60 + 1,
"value61": 61 + 1,
"value62": 62 + 1,
"value63": 63 + 1,
"value64": 64 + 1,
"value65": 65 + 1,
"value66": 66 + 1,
"value67": 67 + 1,
"value68": 68 + 1,
"value69": 69 + 1,
"value70": 70 + 1,
"value71": 71 + 1,
"value72": 72 + 1,
"value73": 73 + 1,
"value74": 74 + 1,
"value75": 75 + 1,
"value76": 76 + 1,
"value77": 77 + 1,
"value78": 78 + 1,
"value79": 79 + 1,
"value80": 80 + 1,
"value81": 81 + 1,
"value82": 82 + 1,
"value83": 83 + 1,
"value84": 84 + 1,
"value85": 85 + 1,
"value86": 86 + 1,
"value87": 87 + 1,
"value88": 88 + 1,
"value89": 89 + 1,
"value90": 90 + 1,
"value91": 91 + 1,
"value92": 92 + 1,
"value93": 93 + 1,
"value94": 94 + 1,
"value95": 95 + 1,
"value96": 96 + 1,
"value97": 97 + 1,
"value98": 98 + 1,
"value99": 99 + 1,
"value100": 100 + 1,
"value101": 101 + 1,
"value102": 102 + 1,
"value103": 103 + 1,
"value104": 104 + 1,
"value105": 105 + 1,
"value106": 106 + 1,
"value107": 107 + 1,
"value108": 108 + 1,
"value109": 109 + 1,
"value110": 110 + 1,
"value111": 111 + 1,
"value112": 112 + 1,
"value113": 113 + 1,
"value114": 114 + 1,
"value115": 115 + 1,
"value116": 116 + 1,
"value117": 117 + 1,
"value118": 118 + 1,
"value119": 119 + 1,
"value120": 120 + 1,
"value121": 121 + 1,
"value122": 122 + 1,
"value123": 123 + 1,
"value124": 124 + 1,
"value125": 125 + 1,
"value126": 126 + 1,
"value127": 127 + 1,
"value128": 128 + 1,
"value129": 129 + 1,
"value130": 130 + 1,
"value131": 131 + 1,
"value132": 132 + 1,
"value133": 133 + 1,
"value134": 134 + 1,
"value135": 135 + 1,
"value136": 136 + 1,
"value137": 137 + 1,
"value138": 138 + 1,
"value139": 139 + 1,
"value140": 140 + 1,
"value141": 141 + 1,
"value142": 142 + 1,
"value143": 143 + 1,
"value144": 144 + 1,
"value145": 145 + 1,
"value146": 146 + 1,
"value147": 147 + 1,
"value148": 148 + 1,
"value149": 149 + 1,
"value150": 150 + 1,
"value151": 151 + 1,
"value152": 152 + 1,
"value153": 153 + 1,
"value154": 154 + 1,
"value155": 155 + 1,
"value156": 156 + 1,
"value157": 157 + 1,
"value158": 158 + 1,
"value159": 159 + 1,
"value160": 160 + 1,
"value161": 161 + 1,
"value162": 162 + 1,
"value163": 163 + 1,
"value164": 164 + 1,
"value165": 165 + 1,
"value166": 166 + 1,
"value167": 167 + 1,
"value168": 168 + 1,
"value169": 169 + 1,
"value170": 170 + 1,
"value171": 171 + 1,
"value172": 172 + 1,
"value173": 173 + 1,
"value174": 174 + 1,
"value175": 175 + 1,
"value176": 176 + 1,
"value177": 177 + 1,
"value178": 178 + 1,
"value179": 179 + 1,
"value180": 180 + 1,
"value181": 181 + 1,
"value182": 182 + 1,
"value183": 183 + 1,
"value184": 184 + 1,
"value185": 185 + 1,
"value186": 186 + 1,
"value187": 187 + 1,
"value188": 188 + 1,
"value189": 189 + 1,
"value190": 190 + 1,
"value191": 191 + 1,
"value192": 192 + 1,
"value193": 193 + 1,
"value194": 194 + 1,
"value195": 195 + 1,
"value196": 196 + 1,
"value197": 197 + 1,
"value198": 198 + 1,
"value199": 199 + 1,
"value200": 200 + 1,
"value201": 201 + 1,
"value202": 202 + 1,
"value203": 203 + 1,
"value204": 204 + 1,
"value205": 205 + 1,
"value206": 206 + 1,
"value207": 207 + 1,
"value208": 208 + 1,
"value209": 209 + 1,
"value210": 210 + 1,
"value211": 211 + 1,
"value212": 212 + 1,
"value213": 213 + 1,
"value214": 214 + 1,
"value215": 215 + 1,
"value216": 216 + 1,
"value217": 217 + 1,
"value218": 218 + 1,
"value219": 219 + 1,
"value220": 220 + 1,
"value221": 221 + 1,
"value222": 222 + 1,
"value223": 223 + 1,
"value224": 224 + 1,
"value225": 225 + 1,
"value226": 226 + 1,
"value227": 227 + 1,
"value228": 228 + 1,
"value229": 229 + 1,
"value230": 230 + 1,
"value231": 231 + 1,
"value232": 232 + 1,
"value233": 233 + 1,
"value234": 234 + 1,
"value235": 235 + 1,
"value236": 236 + 1,
"value237": 237 + 1,
"value238": 238 + 1,
"value239": 239 + 1,
"value240": 240 + 1,
"value241": 241 + 1,
"value242": 242 + 1,
"value243": 243 + 1,
"value244": 244 + 1,
"value245": 245 + 1,
"value246": 246 + 1,
"value247": 247 + 1,
"value248": 248 + 1,
"value249": 249 + 1,
"value250": 250 + 1,
"value251": 251 + 1,
"value252": 252 + 1,
"value253": 253 + 1,
"value254": 254 + 1,
"value255": 255 + 1,
"value256": 256 + 1,
"value257": 257 + 1,
"value258": 258 + 1,
"value259": 259 + 1,
"value260": 260 + 1,
"value261": 261 + 1,
"value262": 262 + 1,
"value263": 263 + 1,
"value264": 264 + 1,
"value265": 265 + 1,
"value266": 266 + 1,
"value267": 267 + 1,
"value268": 268 + 1,
"value269": 269 + 1,
"value270": 270 + 1,
"value271": 271 + 1,
"value272": 272 + 1,
"value273": 273 + 1,
"value274": 274 + 1,
"value275": 275 + 1,
"value276": 276 + 1,
"value277": 277 + 1,
"value278": 278 + 1,
"value279": 279 + 1,
"value280": 280 + 1,
"value281": 281 + 1,
"value282": 282 + 1,
"value283": 283 + 1,
"value284": 284 + 1,
"value285": 285 + 1,
"value286": 286 + 1,
"value287": 287 + 1,
"value288": 288 + 1,
"value289": 289 + 1,
"value290": 290 + 1,
"value291": 291 + 1,
"value292": 292 + 1,
"value293": 293 + 1,
"value294": 294 + 1,
"value295": 295 + 1,
"value296": 296 + 1,
"value297": 297 + 1,
"value298": 298 + 1,
"value299": 299 + 1,
"value300": 300 + 1,
"value301": 301 + 1,
"value302": 302 + 1,
"value303": 303 + 1,
"value304": 304 + 1,
"value305": 305 + 1,
"value306": 306 + 1,
"value307": 307 + 1,
"value308": 308 + 1,
"value309": 309 + 1,
"value310": 310 + 1,
"value311": 311 + 1,
"value312": 312 + 1,
"value313": 313 + 1,
"value314": 314 + 1,
"value315": 315 + 1,
"value316": 316 + 1,
"value317": 317 + 1,
"value318": 318 + 1,
"value319": 319 + 1,
"value320": 320 + 1,
"value321": 321 + 1,
"value322": 322 + 1,
"value323": 323 + 1,
"value324": 324 + 1,
"value325": 325 + 1,
"value326": 326 + 1,
"value327": 327 + 1,
"value328": 328 + 1,
"value329": 329 + 1,
"value330": 330 + 1,
"value331": 331 + 1,
"value332": 332 + 1,
"value333": 333 + 1,
"value334": 334 + 1,
"value335": 335 + 1,
"value336": 336 + 1,
"value337": 337 + 1,
"value338": 338 + 1,
"value339": 339 + 1,
"value340": 340 + 1,
"value341": 341 + 1,
"value342": 342 + 1,
"value343": 343 + 1,
"value344": 344 + 1,
"value345": 345 + 1,
"value346": 346 + 1,
"value347": 347 + 1,
"value348": 348 + 1,
"value349": 349 + 1,
"value350": 350 + 1,
"value351": 351 + 1,
"value352": 352 + 1,
"value353": 353 + 1,
"value354": 354 + 1,
"value355": 355 + 1,
"value356": 356 + 1,
"value357": 357 + 1,
"value358": 358 + 1,
"value359": 359 + 1,
"value360": 360 + 1,
"value361": 361 + 1,
"value362": 362 + 1,
"value363": 363 + 1,
"value364": 364 + 1,
"value365": 365 + 1,
"value366": 366 + 1,
"value367": 367 + 1,
"value368": 368 + 1,
"value369": 369 + 1,
"value370": 370 + 1,
"value371": 371 + 1,
"value372": 372 + 1,
"value373": 373 + 1,
"value374": 374 + 1,
"value375": 375 + 1,
"value376": 376 + 1,
"value377": 377 + 1,
"value378": 378 + 1,
"value379": 379 + 1,
"value380": 380 + 1,
"value381": 381 + 1,
"value382": 382 + 1,
"value383": 383 + 1,
"value384": 384 + 1,
"value385": 385 + 1,
"value386": 386 + 1,
"value387": 387 + 1,
"value388": 388 + 1,
"value389": 389 + 1,
"value390": 390 + 1,
"value391": 391 + 1,
"value392": 392 + 1,
"value393": 393 + 1,
"value394": 394 + 1,
"value395": 395 + 1,
"value396": 396 + 1,
"value397": 397 + 1,
"value398": 398 + 1,
"value399": 399 + 1,
"value400": 400 + 1,
"value401": 401 + 1,
"value402": 402 + 1,
"value403": 403 + 1,
"value404": 404 + 1,
"value405": 405 + 1,
"value406": 406 + 1,
"value407": 407 + 1,
"value408": 408 + 1,
"value409": 409 + 1,
"value410": 410 + 1,
"value411": 411 + 1,
"value412": 412 + 1,
"value413": 413 + 1,
"value414": 414 + 1,
"value415": 415 + 1,
"value416": 416 + 1,
"value417": 417 + 1,
"value418": 418 + 1,
"value419": 419 + 1,
"value420": 420 + 1,
"value421": 421 + 1,
"value422": 422 + 1,
"value423": 423 + 1,
"value424": 424 + 1,
"value425": 425 + 1,
"value426": 426 + 1,
"value427": 427 + 1,
"value428": 428 + 1,
"value429": 429 + 1,
"value430": 430 + 1,
"value431": 431 + 1,
"value432": 432 + 1,
"value433": 433 + 1,
"value434": 434 + 1,
"value435": 435 + 1,
"value436": 436 + 1,
"value437": 437 + 1,
"value438": 438 + 1,
"value439": 439 + 1,
"value440": 440 + 1,
"value441": 441 + 1,
"value442": 442 + 1,
"value443": 443 + 1,
"value444": 444 + 1,
"value445": 445 + 1,
"value446": 446 + 1,
"value447": 447 + 1,
"value448": 448 + 1,
"value449": 449 + 1,
"value450": 450 + 1,
"value451": 451 + 1,
"value452": 452 + 1,
"value453": 453 + 1,
"value454": 454 + 1,
"value455": 455 + 1,
"value456": 456 + 1,
"value457": 457 + 1,
"value458": 458 + 1,
"value459": 459 + 1,
"value460": 460 + 1,
"value461": 461 + 1,
"value462": 462 + 1,
"value463": 463 + 1,
"value464": 464 + 1,
"value465": 465 + 1,
"value466": 466 + 1,
"value467": 467 + 1,
"value468": 468 + 1,
"value469": 469 + 1,
"value470": 470 + 1,
"value471": 471 + 1,
"value472": 472 + 1,
"value473": 473 + 1,
"value474": 474 + 1,
"value475": 475 + 1,
"value476": 476 + 1,
"value477": 477 + 1,
"value478": 478 + 1,
"value479": 479 + 1,
"value480": 480 + 1,
"value481": 481 + 1,
"value482": 482 + 1,
"value483": 483 + 1,
"value484": 484 + 1,
"value485": 485 + 1,
"value486": 486 + 1,
"value487": 487 + 1,
"value488": 488 + 1,
"value489": 489 + 1,
"value490": 490 + 1,
"value491": 491 + 1,
"value492": 492 + 1,
"value493": 493 + 1,
"value494": 494 + 1,
"value495": 495 + 1,
"value496": 496 + 1,
"value497": 497 + 1,
"value498": 498 + 1,
"value499": 499 + 1,
"value500": 500 + 1,
"value501": 501 + 1,
"value502": 502 + 1,
}
import sys
if sys.version < (3, 0):
# Python 2.7 is funky with values.values() ordering
assert sorted(values.values())[1:-2] == list(range(4, 502 + 1))
else:
assert list(values.values())[1:] == list(range(3, 502 + 2))
# Try a long dictionary that fails because we have a binary op.
# We can get a expr32 grouping speedup
# which is slower than if this were all constant.
# The above was not implemented at the time this test was written.
values = {
"value1": a + 1, # This is a binary op not consant
"value2": 2,
"value3": 3,
"value4": 4,
"value5": 5,
"value6": 6,
"value7": 7,
"value8": 8,
"value9": 9,
"value10": 10,
"value11": 11,
"value12": 12,
"value13": 13,
"value14": 14,
"value15": 15,
"value16": 16,
"value17": 17,
"value18": 18,
"value19": 19,
"value20": 20,
"value21": 21,
"value22": 22,
"value23": 23,
"value24": 24,
"value25": 25,
"value26": 26,
"value27": 27,
"value28": 28,
"value29": 29,
"value30": 30,
"value31": 31,
"value32": 32,
"value33": 33,
}
assert sorted(values.values())[1:] == list(range(2, 34))

View File

@@ -0,0 +1,721 @@
# Long lists pose a slowdown in uncompiling.
"This program is self-checking!"
# Try an empty list to check that long-matching detection doesn't mess that up.
# In theory this should work even though we put cap on short lists which
# is checked below.
x = []
assert len(x) == 0 and isinstance(x, list)
# Try an short list to check that long-matching detection doesn't mess that up.
# This is a more general situation of the above.
x = [1, 1, 1]
# Until we have better "and" rules (which we have
# around, but not in decompyle3 or uncompyle6 yet)
# avoid 3-term "and"s
assert len(x) == 3
assert isinstance(x, list) and all(x)
# fmt: off
# Try a long list. This should not be slow
# as it has been in the past.
x = [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
]
assert all(x)
assert len(x) == 300 and isinstance(x, list)
# Python before 2.7 doesn't have sets literal
# # Try a long set. This should not be slow
# # as it has been in the past.
# x = {
# 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
# 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
# 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
# 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
# 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
# 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
# 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
# 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
# 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
# }
# assert x == {1} and isinstance(x, set)
# Try using variables rather than constants
a = 1
# First, a list
x = [
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a,
]
assert all(x)
assert len(x) == 300 and isinstance(x, list)
# Next, a set
# x = {
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# a, a, a, a, a, a, a, a, a, a,
# }
# assert x == {1} and isinstance(x, set)
# Check some dictionary keys.
# Ensure that in dictionary we produce quoted strings
x = {
"b": 1,
"c": 2,
"e": 3,
"g": 6,
"h": 7,
"j": 9,
"k": 11,
"return": 12,
}
assert sorted(x.keys()) == ["b", "c", "e", "g", "h", "j", "k", "return"]
# Ensure that in dictionary we produce integers, not strings
x = {1: 2, 3: 4}
assert tuple(x.keys()) == (1, 3)
# Try a long dictionary.
# This should not be slow as it has been in the past
values = {
"value1": x, # Note this is LOAD_NAME
"value2": 2 + 1, # Constant should be folded into "LOAD_CONST"
"value3": 3 + 1,
"value4": 4 + 1,
"value5": 5 + 1,
"value6": 6 + 1,
"value7": 7 + 1,
"value8": 8 + 1,
"value9": 9 + 1,
"value10": 10 + 1,
"value11": 11 + 1,
"value12": 12 + 1,
"value13": 13 + 1,
"value14": 14 + 1,
"value15": 15 + 1,
"value16": 16 + 1,
"value17": 17 + 1,
"value18": 18 + 1,
"value19": 19 + 1,
"value20": 20 + 1,
"value21": 21 + 1,
"value22": 22 + 1,
"value23": 23 + 1,
"value24": 24 + 1,
"value25": 25 + 1,
"value26": 26 + 1,
"value27": 27 + 1,
"value28": 28 + 1,
"value29": 29 + 1,
"value30": 30 + 1,
"value31": 31 + 1,
"value32": 32 + 1,
"value33": 33 + 1,
"value34": 34 + 1,
"value35": 35 + 1,
"value36": 36 + 1,
"value37": 37 + 1,
"value38": 38 + 1,
"value39": 39 + 1,
"value40": 40 + 1,
"value41": 41 + 1,
"value42": 42 + 1,
"value43": 43 + 1,
"value44": 44 + 1,
"value45": 45 + 1,
"value46": 46 + 1,
"value47": 47 + 1,
"value48": 48 + 1,
"value49": 49 + 1,
"value50": 50 + 1,
"value51": 51 + 1,
"value52": 52 + 1,
"value53": 53 + 1,
"value54": 54 + 1,
"value55": 55 + 1,
"value56": 56 + 1,
"value57": 57 + 1,
"value58": 58 + 1,
"value59": 59 + 1,
"value60": 60 + 1,
"value61": 61 + 1,
"value62": 62 + 1,
"value63": 63 + 1,
"value64": 64 + 1,
"value65": 65 + 1,
"value66": 66 + 1,
"value67": 67 + 1,
"value68": 68 + 1,
"value69": 69 + 1,
"value70": 70 + 1,
"value71": 71 + 1,
"value72": 72 + 1,
"value73": 73 + 1,
"value74": 74 + 1,
"value75": 75 + 1,
"value76": 76 + 1,
"value77": 77 + 1,
"value78": 78 + 1,
"value79": 79 + 1,
"value80": 80 + 1,
"value81": 81 + 1,
"value82": 82 + 1,
"value83": 83 + 1,
"value84": 84 + 1,
"value85": 85 + 1,
"value86": 86 + 1,
"value87": 87 + 1,
"value88": 88 + 1,
"value89": 89 + 1,
"value90": 90 + 1,
"value91": 91 + 1,
"value92": 92 + 1,
"value93": 93 + 1,
"value94": 94 + 1,
"value95": 95 + 1,
"value96": 96 + 1,
"value97": 97 + 1,
"value98": 98 + 1,
"value99": 99 + 1,
"value100": 100 + 1,
"value101": 101 + 1,
"value102": 102 + 1,
"value103": 103 + 1,
"value104": 104 + 1,
"value105": 105 + 1,
"value106": 106 + 1,
"value107": 107 + 1,
"value108": 108 + 1,
"value109": 109 + 1,
"value110": 110 + 1,
"value111": 111 + 1,
"value112": 112 + 1,
"value113": 113 + 1,
"value114": 114 + 1,
"value115": 115 + 1,
"value116": 116 + 1,
"value117": 117 + 1,
"value118": 118 + 1,
"value119": 119 + 1,
"value120": 120 + 1,
"value121": 121 + 1,
"value122": 122 + 1,
"value123": 123 + 1,
"value124": 124 + 1,
"value125": 125 + 1,
"value126": 126 + 1,
"value127": 127 + 1,
"value128": 128 + 1,
"value129": 129 + 1,
"value130": 130 + 1,
"value131": 131 + 1,
"value132": 132 + 1,
"value133": 133 + 1,
"value134": 134 + 1,
"value135": 135 + 1,
"value136": 136 + 1,
"value137": 137 + 1,
"value138": 138 + 1,
"value139": 139 + 1,
"value140": 140 + 1,
"value141": 141 + 1,
"value142": 142 + 1,
"value143": 143 + 1,
"value144": 144 + 1,
"value145": 145 + 1,
"value146": 146 + 1,
"value147": 147 + 1,
"value148": 148 + 1,
"value149": 149 + 1,
"value150": 150 + 1,
"value151": 151 + 1,
"value152": 152 + 1,
"value153": 153 + 1,
"value154": 154 + 1,
"value155": 155 + 1,
"value156": 156 + 1,
"value157": 157 + 1,
"value158": 158 + 1,
"value159": 159 + 1,
"value160": 160 + 1,
"value161": 161 + 1,
"value162": 162 + 1,
"value163": 163 + 1,
"value164": 164 + 1,
"value165": 165 + 1,
"value166": 166 + 1,
"value167": 167 + 1,
"value168": 168 + 1,
"value169": 169 + 1,
"value170": 170 + 1,
"value171": 171 + 1,
"value172": 172 + 1,
"value173": 173 + 1,
"value174": 174 + 1,
"value175": 175 + 1,
"value176": 176 + 1,
"value177": 177 + 1,
"value178": 178 + 1,
"value179": 179 + 1,
"value180": 180 + 1,
"value181": 181 + 1,
"value182": 182 + 1,
"value183": 183 + 1,
"value184": 184 + 1,
"value185": 185 + 1,
"value186": 186 + 1,
"value187": 187 + 1,
"value188": 188 + 1,
"value189": 189 + 1,
"value190": 190 + 1,
"value191": 191 + 1,
"value192": 192 + 1,
"value193": 193 + 1,
"value194": 194 + 1,
"value195": 195 + 1,
"value196": 196 + 1,
"value197": 197 + 1,
"value198": 198 + 1,
"value199": 199 + 1,
"value200": 200 + 1,
"value201": 201 + 1,
"value202": 202 + 1,
"value203": 203 + 1,
"value204": 204 + 1,
"value205": 205 + 1,
"value206": 206 + 1,
"value207": 207 + 1,
"value208": 208 + 1,
"value209": 209 + 1,
"value210": 210 + 1,
"value211": 211 + 1,
"value212": 212 + 1,
"value213": 213 + 1,
"value214": 214 + 1,
"value215": 215 + 1,
"value216": 216 + 1,
"value217": 217 + 1,
"value218": 218 + 1,
"value219": 219 + 1,
"value220": 220 + 1,
"value221": 221 + 1,
"value222": 222 + 1,
"value223": 223 + 1,
"value224": 224 + 1,
"value225": 225 + 1,
"value226": 226 + 1,
"value227": 227 + 1,
"value228": 228 + 1,
"value229": 229 + 1,
"value230": 230 + 1,
"value231": 231 + 1,
"value232": 232 + 1,
"value233": 233 + 1,
"value234": 234 + 1,
"value235": 235 + 1,
"value236": 236 + 1,
"value237": 237 + 1,
"value238": 238 + 1,
"value239": 239 + 1,
"value240": 240 + 1,
"value241": 241 + 1,
"value242": 242 + 1,
"value243": 243 + 1,
"value244": 244 + 1,
"value245": 245 + 1,
"value246": 246 + 1,
"value247": 247 + 1,
"value248": 248 + 1,
"value249": 249 + 1,
"value250": 250 + 1,
"value251": 251 + 1,
"value252": 252 + 1,
"value253": 253 + 1,
"value254": 254 + 1,
"value255": 255 + 1,
"value256": 256 + 1,
"value257": 257 + 1,
"value258": 258 + 1,
"value259": 259 + 1,
"value260": 260 + 1,
"value261": 261 + 1,
"value262": 262 + 1,
"value263": 263 + 1,
"value264": 264 + 1,
"value265": 265 + 1,
"value266": 266 + 1,
"value267": 267 + 1,
"value268": 268 + 1,
"value269": 269 + 1,
"value270": 270 + 1,
"value271": 271 + 1,
"value272": 272 + 1,
"value273": 273 + 1,
"value274": 274 + 1,
"value275": 275 + 1,
"value276": 276 + 1,
"value277": 277 + 1,
"value278": 278 + 1,
"value279": 279 + 1,
"value280": 280 + 1,
"value281": 281 + 1,
"value282": 282 + 1,
"value283": 283 + 1,
"value284": 284 + 1,
"value285": 285 + 1,
"value286": 286 + 1,
"value287": 287 + 1,
"value288": 288 + 1,
"value289": 289 + 1,
"value290": 290 + 1,
"value291": 291 + 1,
"value292": 292 + 1,
"value293": 293 + 1,
"value294": 294 + 1,
"value295": 295 + 1,
"value296": 296 + 1,
"value297": 297 + 1,
"value298": 298 + 1,
"value299": 299 + 1,
"value300": 300 + 1,
"value301": 301 + 1,
"value302": 302 + 1,
"value303": 303 + 1,
"value304": 304 + 1,
"value305": 305 + 1,
"value306": 306 + 1,
"value307": 307 + 1,
"value308": 308 + 1,
"value309": 309 + 1,
"value310": 310 + 1,
"value311": 311 + 1,
"value312": 312 + 1,
"value313": 313 + 1,
"value314": 314 + 1,
"value315": 315 + 1,
"value316": 316 + 1,
"value317": 317 + 1,
"value318": 318 + 1,
"value319": 319 + 1,
"value320": 320 + 1,
"value321": 321 + 1,
"value322": 322 + 1,
"value323": 323 + 1,
"value324": 324 + 1,
"value325": 325 + 1,
"value326": 326 + 1,
"value327": 327 + 1,
"value328": 328 + 1,
"value329": 329 + 1,
"value330": 330 + 1,
"value331": 331 + 1,
"value332": 332 + 1,
"value333": 333 + 1,
"value334": 334 + 1,
"value335": 335 + 1,
"value336": 336 + 1,
"value337": 337 + 1,
"value338": 338 + 1,
"value339": 339 + 1,
"value340": 340 + 1,
"value341": 341 + 1,
"value342": 342 + 1,
"value343": 343 + 1,
"value344": 344 + 1,
"value345": 345 + 1,
"value346": 346 + 1,
"value347": 347 + 1,
"value348": 348 + 1,
"value349": 349 + 1,
"value350": 350 + 1,
"value351": 351 + 1,
"value352": 352 + 1,
"value353": 353 + 1,
"value354": 354 + 1,
"value355": 355 + 1,
"value356": 356 + 1,
"value357": 357 + 1,
"value358": 358 + 1,
"value359": 359 + 1,
"value360": 360 + 1,
"value361": 361 + 1,
"value362": 362 + 1,
"value363": 363 + 1,
"value364": 364 + 1,
"value365": 365 + 1,
"value366": 366 + 1,
"value367": 367 + 1,
"value368": 368 + 1,
"value369": 369 + 1,
"value370": 370 + 1,
"value371": 371 + 1,
"value372": 372 + 1,
"value373": 373 + 1,
"value374": 374 + 1,
"value375": 375 + 1,
"value376": 376 + 1,
"value377": 377 + 1,
"value378": 378 + 1,
"value379": 379 + 1,
"value380": 380 + 1,
"value381": 381 + 1,
"value382": 382 + 1,
"value383": 383 + 1,
"value384": 384 + 1,
"value385": 385 + 1,
"value386": 386 + 1,
"value387": 387 + 1,
"value388": 388 + 1,
"value389": 389 + 1,
"value390": 390 + 1,
"value391": 391 + 1,
"value392": 392 + 1,
"value393": 393 + 1,
"value394": 394 + 1,
"value395": 395 + 1,
"value396": 396 + 1,
"value397": 397 + 1,
"value398": 398 + 1,
"value399": 399 + 1,
"value400": 400 + 1,
"value401": 401 + 1,
"value402": 402 + 1,
"value403": 403 + 1,
"value404": 404 + 1,
"value405": 405 + 1,
"value406": 406 + 1,
"value407": 407 + 1,
"value408": 408 + 1,
"value409": 409 + 1,
"value410": 410 + 1,
"value411": 411 + 1,
"value412": 412 + 1,
"value413": 413 + 1,
"value414": 414 + 1,
"value415": 415 + 1,
"value416": 416 + 1,
"value417": 417 + 1,
"value418": 418 + 1,
"value419": 419 + 1,
"value420": 420 + 1,
"value421": 421 + 1,
"value422": 422 + 1,
"value423": 423 + 1,
"value424": 424 + 1,
"value425": 425 + 1,
"value426": 426 + 1,
"value427": 427 + 1,
"value428": 428 + 1,
"value429": 429 + 1,
"value430": 430 + 1,
"value431": 431 + 1,
"value432": 432 + 1,
"value433": 433 + 1,
"value434": 434 + 1,
"value435": 435 + 1,
"value436": 436 + 1,
"value437": 437 + 1,
"value438": 438 + 1,
"value439": 439 + 1,
"value440": 440 + 1,
"value441": 441 + 1,
"value442": 442 + 1,
"value443": 443 + 1,
"value444": 444 + 1,
"value445": 445 + 1,
"value446": 446 + 1,
"value447": 447 + 1,
"value448": 448 + 1,
"value449": 449 + 1,
"value450": 450 + 1,
"value451": 451 + 1,
"value452": 452 + 1,
"value453": 453 + 1,
"value454": 454 + 1,
"value455": 455 + 1,
"value456": 456 + 1,
"value457": 457 + 1,
"value458": 458 + 1,
"value459": 459 + 1,
"value460": 460 + 1,
"value461": 461 + 1,
"value462": 462 + 1,
"value463": 463 + 1,
"value464": 464 + 1,
"value465": 465 + 1,
"value466": 466 + 1,
"value467": 467 + 1,
"value468": 468 + 1,
"value469": 469 + 1,
"value470": 470 + 1,
"value471": 471 + 1,
"value472": 472 + 1,
"value473": 473 + 1,
"value474": 474 + 1,
"value475": 475 + 1,
"value476": 476 + 1,
"value477": 477 + 1,
"value478": 478 + 1,
"value479": 479 + 1,
"value480": 480 + 1,
"value481": 481 + 1,
"value482": 482 + 1,
"value483": 483 + 1,
"value484": 484 + 1,
"value485": 485 + 1,
"value486": 486 + 1,
"value487": 487 + 1,
"value488": 488 + 1,
"value489": 489 + 1,
"value490": 490 + 1,
"value491": 491 + 1,
"value492": 492 + 1,
"value493": 493 + 1,
"value494": 494 + 1,
"value495": 495 + 1,
"value496": 496 + 1,
"value497": 497 + 1,
"value498": 498 + 1,
"value499": 499 + 1,
"value500": 500 + 1,
"value501": 501 + 1,
"value502": 502 + 1,
}
assert len(values.values()) == 502
# Try a long dictionary that fails because we have a binary op.
# We can get a expr32 grouping speedup
# which is slower than if this were all constant.
# The above was not implemented at the time this test was written.
values = {
"value1": a + 1, # This is a binary op not consant
"value2": 2,
"value3": 3,
"value4": 4,
"value5": 5,
"value6": 6,
"value7": 7,
"value8": 8,
"value9": 9,
"value10": 10,
"value11": 11,
"value12": 12,
"value13": 13,
"value14": 14,
"value15": 15,
"value16": 16,
"value17": 17,
"value18": 18,
"value19": 19,
"value20": 20,
"value21": 21,
"value22": 22,
"value23": 23,
"value24": 24,
"value25": 25,
"value26": 26,
"value27": 27,
"value28": 28,
"value29": 29,
"value30": 30,
"value31": 31,
"value32": 32,
"value33": 33,
}
assert len(values.values()) == 33

View File

@@ -1,12 +1,12 @@
# Bug in Python 3
# Python 3.3+
# mklambda ::= LOAD_LAMBDA LOAD_CONST MAKE_FUNCTION_0
# lambda_body ::= LOAD_LAMBDA LOAD_CONST MAKE_FUNCTION_0
# Python 3.0 .. 3.2
# mklambda ::= LOAD_LAMBDA MAKE_FUNCTION_0
# lambda_body ::= LOAD_LAMBDA MAKE_FUNCTION_0
# _mklambda ::= mklambda
# expr ::= _mklambda
# _lambda_body ::= lambda_body
# expr ::= _lambda_body
# kwarg ::= LOAD_CONST expr
# exprlist ::= exprlist expr
# call_function ::= expr kwarg CALL_FUNCTION_256

View File

@@ -1,22 +1,22 @@
# 2.6.9 asynchat.py
# 2.6 added:
# return_stmt ::= ret_expr RETURN_END_IF come_from_pop
def initiate_send(self):
# return_stmt ::= return_expr RETURN_END_IF come_from_pop
def initiate_send(self, x):
while self:
if self:
x = 'a'
else:
del self.producer_fifo[0]
return
return x
# 2.6.9 contextlib.py
# Bug was in return exc, so added:
# return_stmt ::= ret_expr RETURN_VALUE_IF come_from_pop
# return_stmt ::= return_expr RETURN_VALUE_IF come_from_pop
def __exit__(self, type, value, traceback):
try:
raise RuntimeError
except StopIteration:
return exc
return value
except:
raise

Some files were not shown because too many files have changed in this diff Show More