Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] RFT mode does not update class attribute usage in subclasses #1944

Open
porthole-ascend-cinnamon opened this issue Oct 7, 2024 · 1 comment
Labels

Comments

@porthole-ascend-cinnamon
Copy link

porthole-ascend-cinnamon commented Oct 7, 2024

As the title says, in RFT mode attributes in the base class are renamed, but their usage in the subclass aren't.

Environment:

INFO     Python 3.12.6
INFO     Pyarmor 8.5.11 (pro)
INFO     Platform linux.x86_64

Steps to reproduce

  1. Create a file main.py
class A:
    def __init__(self, x):
        self.x = x

class B(A):
    def get_x(self):
        return self.x

if __name__ == '__main__':
    b = B(1)
    print(b.get_x())
  1. pyarmor cfg enable_rft=1 trace_rft=1
  2. pyarmor gen main.py
  3. python dist/main.py

Result:

Traceback (most recent call last):
  File "<frozen __main__>", line 3, in <module>
  File "<frozen main>", line 13, in <module>
  File "<frozen main>", line 8, in pyarmor__4
AttributeError: 'pyarmor__3' object has no attribute 'x'

RFT trace

pyarmor__6, = __assert_armored__(b'\x84d\xd4p\x94\xe1XhU\x07\xd1\xc5)#\x19\x9eS\xcd?\x90~[R\xe74\x9aj')

class pyarmor__1:

    def __init__(self, x):
        self.pyarmor__2 = x

class pyarmor__3(pyarmor__1):

    def pyarmor__4(self):
        return self.x
if __name__ == '__main__':
    pyarmor__5 = pyarmor__3(1)
    pyarmor__6(pyarmor__5.pyarmor__4())

Expected result:
return self.x is changed to return self.pyarmor__2

Additional notes:
Duplicating __init__ in class B fixes the issue but isn't a great solution.
Same issue appears when calling methods defined in parent class, and adding them to exclude table kinda defeats the purpose.
It would be great if subclass support could be added.

@jondy
Copy link
Contributor

jondy commented Oct 8, 2024

Got it, thanks.

It will be fixed in next release (about in this month)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants