diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2020-12-21 07:15:11 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-01-10 09:46:18 -0500 |
commit | 868d86878da0446c2776b008652baa6e5e87feb7 (patch) | |
tree | 5ea7104468bafa0c710a60309c34fb20b469683a | |
parent | d230aca5a299373d784a1eb29e64587308726ca9 (diff) | |
download | python-coveragepy-git-868d86878da0446c2776b008652baa6e5e87feb7.tar.gz |
show_pyc: Flags changed in 3.9
-rw-r--r-- | lab/show_pyc.py | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/lab/show_pyc.py b/lab/show_pyc.py index 7573c1c3..b4dc7cd7 100644 --- a/lab/show_pyc.py +++ b/lab/show_pyc.py @@ -1,6 +1,14 @@ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt +""" +Dump the contents of a .pyc file. + +The output will only be correct if run with the same version of Python that +produced the .pyc. + +""" + import binascii import dis import marshal @@ -55,15 +63,31 @@ CO_FLAGS = [ ('CO_ITERABLE_COROUTINE', 0x00100), ('CO_ASYNC_GENERATOR', 0x00200), ('CO_GENERATOR_ALLOWED', 0x01000), - ('CO_FUTURE_DIVISION', 0x02000), - ('CO_FUTURE_ABSOLUTE_IMPORT', 0x04000), - ('CO_FUTURE_WITH_STATEMENT', 0x08000), - ('CO_FUTURE_PRINT_FUNCTION', 0x10000), - ('CO_FUTURE_UNICODE_LITERALS', 0x20000), - ('CO_FUTURE_BARRY_AS_BDFL', 0x40000), - ('CO_FUTURE_GENERATOR_STOP', 0x80000), ] +if sys.version_info < (3, 9): + CO_FLAGS += [ + ('CO_FUTURE_DIVISION', 0x02000), + ('CO_FUTURE_ABSOLUTE_IMPORT', 0x04000), + ('CO_FUTURE_WITH_STATEMENT', 0x08000), + ('CO_FUTURE_PRINT_FUNCTION', 0x10000), + ('CO_FUTURE_UNICODE_LITERALS', 0x20000), + ('CO_FUTURE_BARRY_AS_BDFL', 0x40000), + ('CO_FUTURE_GENERATOR_STOP', 0x80000), + ] +else: + CO_FLAGS += [ + ('CO_FUTURE_DIVISION', 0x0020000), + ('CO_FUTURE_ABSOLUTE_IMPORT', 0x0040000), + ('CO_FUTURE_WITH_STATEMENT', 0x0080000), + ('CO_FUTURE_PRINT_FUNCTION', 0x0100000), + ('CO_FUTURE_UNICODE_LITERALS', 0x0200000), + ('CO_FUTURE_BARRY_AS_BDFL', 0x0400000), + ('CO_FUTURE_GENERATOR_STOP', 0x0800000), + ('CO_FUTURE_ANNOTATIONS', 0x1000000), + ] + + def show_code(code, indent='', number=None): label = "" if number is not None: |