rocky / python-uncompyle6

A cross-version Python bytecode decompiler
GNU General Public License v3.0
3.74k stars 408 forks source link

KeyError: '3.11.3' #460

Closed Moosems closed 1 year ago

Moosems commented 1 year ago

Description

When trying to decompile newer bytecodes I get this error (I made the following code to test uncompyle 6).

How to Reproduce

test.py

from account import Account

# Create an instance of Account
my_account = Account("John Doe", 1000.0)

# Deposit some money
my_account.deposit(500.0)

# Withdraw some money
successful_withdrawal = my_account.withdraw(2000.0)

# Print account information
print(f"Account Owner: {my_account.owner}")
print(f"Account Balance: {my_account.balance}")
print(f"Withdrawal Successful: {successful_withdrawal}")

account.py

from __future__ import annotations

class Account:
    """A class representing a bank account."""

    def __init__(self, owner: str, balance: float = 0.0):
        """Initialize the Account object with an owner and balance."""
        self.owner = owner
        self.balance = balance

    def deposit(self, amount: float) -> None:
        """Deposit the specified amount into the account."""
        if amount > 0:
            self.balance += amount

    def withdraw(self, amount: float) -> bool:
        """
        Withdraw the specified amount from the account.
        Returns True if successful, False if there are insufficient funds.
        """
        if amount <= self.balance:
            self.balance -= amount
            return True
        return False
$ uncompyle6 .
...
$

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

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/bin/uncompyle6", line 5, in <module>
    from uncompyle6.bin.uncompile import main_bin
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/uncompyle6/__init__.py", line 53, in <module>
    import uncompyle6.semantics.pysource
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/uncompyle6/semantics/pysource.py", line 141, in <module>
    from uncompyle6.parsers.treenode import SyntaxTree
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/uncompyle6/parsers/treenode.py", line 3, in <module>
    from uncompyle6.scanners.tok import NoneToken
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/uncompyle6/scanners/tok.py", line 200, in <module>
    NoneToken = Token("LOAD_CONST", offset=-1, attr=None, pattr=None)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/uncompyle6/scanners/tok.py", line 86, in __init__
    from xdis.std import _std_api
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/xdis/std.py", line 220, in <module>
    _std_api = make_std_api()
               ^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/xdis/std.py", line 218, in make_std_api
    return _StdApi(python_version, variant)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/xdis/std.py", line 73, in __init__
    self.opc = opc = get_opcode_module(python_version, variant)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/xdis/op_imports.py", line 174, in get_opcode_module
    return op_imports[canonic_python_version[vers_str]]
                      ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: '3.11.3'

Expected behavior

Decompiles the bytecode

Environment

None

Please modify for your setup

snaulX commented 1 year ago

Same but I used Python version '3.11.4'

rocky commented 1 year ago

This is not the full output. Read all of the messages output.

Moosems commented 1 year ago

I promise you, that's the full output.

Moosems commented 1 year ago
Moosems-MacBook-Pro:test Moosems$ uncompyle6 .
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/bin/uncompyle6", line 5, in <module>
    from uncompyle6.bin.uncompile import main_bin
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/uncompyle6/__init__.py", line 53, in <module>
    import uncompyle6.semantics.pysource
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/uncompyle6/semantics/pysource.py", line 141, in <module>
    from uncompyle6.parsers.treenode import SyntaxTree
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/uncompyle6/parsers/treenode.py", line 3, in <module>
    from uncompyle6.scanners.tok import NoneToken
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/uncompyle6/scanners/tok.py", line 200, in <module>
    NoneToken = Token("LOAD_CONST", offset=-1, attr=None, pattr=None)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/uncompyle6/scanners/tok.py", line 86, in __init__
    from xdis.std import _std_api
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/xdis/std.py", line 220, in <module>
    _std_api = make_std_api()
               ^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/xdis/std.py", line 218, in make_std_api
    return _StdApi(python_version, variant)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/xdis/std.py", line 73, in __init__
    self.opc = opc = get_opcode_module(python_version, variant)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/xdis/op_imports.py", line 174, in get_opcode_module
    return op_imports[canonic_python_version[vers_str]]
                      ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: '3.11.3'
rocky commented 1 year ago

I promise you, that's the full output.

Ok - sorry. You are using version 3.7.4 and the last released version is 3.9.0 which gives better error messages.

Moosems commented 1 year ago

I installed it from pypi the day I made the issue 🙁.

Tassader commented 1 year ago

I have similar issue. When using python 3.11 pip installs uncompyle6 3.7.4 (as the newest compatible version) and when running uncompyle6 even without any parameters I get the same error as OP

With python 2.7.4 pip installs uncompyle6 3.9.0 that works (so far)

rocky commented 1 year ago

With python 2.7.4 pip installs uncompyle6 3.9.0 that works (so far)

The issue form https://github.com/rocky/python-uncompyle6/blob/master/.github/ISSUE_TEMPLATE/bug-report.md has a section called "WORKAROUNDS". I notice this section was omitted in the origin report. There is a reason why it is useful read all of the instructions and fill out the form correctly.

Maybe the 3 of you can huddle together and work out a solution on your own. One of the features of open-source software is that you have all of the source code at your disposal to try to figure things out. Or maybe you could pool your resources and open a bounty somewhere to have someone else figure this out for you?

Tassader commented 1 year ago

The issue form https://github.com/rocky/python-uncompyle6/blob/master/.github/ISSUE_TEMPLATE/bug-report.md has a section called "WORKAROUNDS". I notice this section was omitted in the origin report. There is a reason why it is useful read all of the instructions and fill out the form correctly.

Maybe the OP did not know about the possibility of such a workaround? (Plus maybe using old version od Python is not a feasible workaround for some people?)

I don't know why you are being rude at people for reporting issues, Is that bad or what?

rocky commented 1 year ago

People are free to report issues, and that is why issues are enabled.

Before reporting features and issues, read, understand, and follow the instructions given in each category. Those who do not, may find their features and issues ignored or closed.