Match case for class items support
mastrolube opened this issue · comments
Hello, I've refactored a little bit my code and found out that pyarmor is not supporting match case
with class items. (I'm on pro version)
That's the error:
patterns may only match literals and attribute lookups
from enum import Enum, auto
class ExampleEnum(Enum):
OPTION_A = auto()
OPTION_B = auto()
OPTION_C = auto()
def example_function(value: ExampleEnum):
match value:
case ExampleEnum.OPTION_A:
# perform action
case ExampleEnum.OPTION_B:
# perform action
case ExampleEnum.OPTION_C:
# perform action
case _:
# default action
What's the reason for that? Will that be supported in the future?
Thanks, Dennis
Can't be reproduced. What I got by Pyarmor 8.5.7 with Python 3.10 in Darwin:
...
class pyarmor__1(pyarmor__6):
pyarmor__2 = pyarmor__7()
pyarmor__3 = pyarmor__7()
pyarmor__4 = pyarmor__7()
def pyarmor__5(value: pyarmor__1):
match value:
case pyarmor__1.pyarmor__2:
pass
case pyarmor__1.pyarmor__3:
pass
case pyarmor__1.pyarmor__4:
pass
case _:
pass
Try to clean local configuration path mv .pyarmor .pyarmor.bak
and test it again.
Hello!
I found out that it's related to: --obf-code 2
pyarmor -d gen -O dist test.py --obf-code 2
where test.py contains the code above
INFO obfuscating file test.py
DEBUG process inline marker
DEBUG parse script
DEBUG process co
DEBUG process attribute
DEBUG unknown error, please check pyarmor.error.log
ERROR patterns may only match literals and attribute lookups
ERROR somthing is wrong
Also there is a typo in somEthing
:)
32972 MainProcess 2024-04-29 19:43:30,352
Traceback (most recent call last):
File "/Users/mastrolube/PycharmProjects/test/.venv/lib/python3.10/site-packages/pyarmor/cli/main.py", line 769, in main
main_entry(sys.argv[1:])
File "/Users/mastrolube/PycharmProjects/test/.venv/lib/python3.10/site-packages/pyarmor/cli/main.py", line 757, in main_entry
return args.func(ctx, args)
File "/Users/mastrolube/PycharmProjects/test/.venv/lib/python3.10/site-packages/pyarmor/cli/main.py", line 249, in cmd_gen
builder.process(options)
File "/Users/mastrolube/PycharmProjects/test/.venv/lib/python3.10/site-packages/pyarmor/cli/generate.py", line 176, in process
self._obfuscate_scripts()
File "/Users/mastrolube/PycharmProjects/test/.venv/lib/python3.10/site-packages/pyarmor/cli/generate.py", line 129, in _obfuscate_scripts
code = Pytransform3.generate_obfuscated_script(self.ctx, r)
File "/Users/mastrolube/PycharmProjects/test/.venv/lib/python3.10/site-packages/pyarmor/cli/core/init.py", line 108, in generate_obfuscated_script
return m.generate_obfuscated_script(ctx, res)
File "", line 711, in generate_obfuscated_script
File "/Users/mastrolube/PycharmProjects/test/.venv/lib/python3.10/site-packages/pyarmor/cli/init.py", line 16, in process
return meth(self, res, *args, **kwargs)
File "", line 533, in process
File "/Users/mastrolube/PycharmProjects/test/.venv/lib/python3.10/site-packages/pyarmor/cli/resource.py", line 158, in recompile
self.mco = compile(mtree, self.frozenname, 'exec', optimize=optimize)
ValueError: patterns may only match literals and attribute lookups
Thanks!
Dennis
Got it. Thanks, all of them will be fixed in next release
Fixed in 8.5.8