Python 3.10 match case fails with '|'
See original GitHub issue-
Nuitka version, full Python version, flavor, OS, etc. as output by this command (it does more than you think, and we are adding more all the time):
python -m nuitka --version 0.7.6 Commercial: None Python: 3.10.2 (main, Mar 5 2022, 23:17:41) [GCC 8.3.0] Flavor: Unknown Executable: /home/david/Dev/python/dev_venv3.10.2/bin/python OS: Linux Arch: x86_64 Distribution: Debian 11
-
How did you install Nuitka and Python
-
Via Pycharm settings
Did you use pip, anaconda, deb, rpm, from source, git clone, then install into a virtualenv or not, this is very important usually. No
-
The specific PyPI names and versions
It should be taken from this output if there specific packages involved, e.g.
numpy
, you are expected to shorten this to the relevant ones.python -m pip freeze appdirs==1.4.4 astroid==2.11.2 black==22.3.0 certifi==2021.10.8 charset-normalizer==2.0.12 click==8.1.2 ConfigUpdater==3.1 crypto==1.4.1 dill==0.3.4 dlib==19.23.1 fs==2.4.15 idna==3.3 isort==5.10.1 lazy-object-proxy==1.7.1 mccabe==0.7.0 mypy==0.942 mypy-extensions==0.4.3 Naked==0.1.31 netifaces==0.11.0 Nuitka==0.7.6 numpy==1.22.3 pathspec==0.9.0 pathvalidate==2.5.0 platformdirs==2.5.1 psutil==5.9.0 pycryptodome==3.14.1 pylint==2.13.4 PySide6==6.2.4 pysqlite3==0.4.7 pytz==2022.1 PyYAML==6.0 requests==2.27.1 shellescape==3.8.1 shiboken6==6.2.4 simplejson==3.17.6 six==1.16.0 toml==0.10.2 tomli==2.0.1 types-simplejson==3.17.4 typing_extensions==4.1.1 urllib3==1.26.9 wrapt==1.14.0 xmltodict==0.12.0
-
Many times when you get an error from Nuitka, your setup may be special
Then even a
print("hello world")
program will not work, please try that and report that instead.
That works!
- Also supply a Short, Self Contained, Correct, Example
from enum import Enum
class strEnum(str, Enum):
def __repr__(self):
return str(self.value)
def __str__(self):
return str(self.value)
@classmethod
def list(cls) -> list[str]:
str_list: list[str] = []
for x in cls:
str_list.append(x.value)
return str_list
class DATATYPE(strEnum):
BLOB = "BLOB"
BOOL = "BOOL"
CHAR = "CHAR"
CURRENCY = "CURRENCY"
FLOAT = "FLOAT"
INTEGER = "INTEGER"
REAL = "REAL"
TEXT = "TEXT"
test_str = DATATYPE.BLOB
match test_str:
case DATATYPE.BLOB | DATATYPE.TEXT :
print(f"DBG {test_str=}")
case _:
print(f"DBG Not Blob")
-
Provide in your issue the Nuitka options used
python -OO -m nuitka test.py
On compile
python -OO -m nuitka test.py Nuitka-Options:INFO: Used command line options: test.py Nuitka-Options:WARNING: You did not specify to follow or include anything but main program. Check options and make sure that is intended. Nuitka-Options:INFO: Detected static libpython to exist, consider ‘–static-libpython=yes’ for better performance, but errors may happen. Nuitka:INFO: Starting Python compilation with Nuitka ‘0.7.6’ on Python ‘3.10’ commercial None. Nuitka-Optimization:WARNING: Problem at ‘test.py:36’ with Match(subject=Name(id=‘test_str’, ctx=Load()), cases=[match_case(pattern=MatchOr(patterns=[MatchClass(cls=Name(id=‘str’, ctx=Load()), patterns=[MatchValue(value=Attribute(value=Name(id=‘DATATYPE’, ctx=Load()), attr=‘BLOB’, ctx=Load()))], kwd_attrs=[], kwd_patterns=[]), MatchClass(cls=Name(id=‘str’, ctx=Load()), patterns=[MatchValue(value=Attribute(value=Name(id=‘DATATYPE’, ctx=Load()), attr=‘TEXT’, ctx=Load()))], kwd_attrs=[], kwd_patterns=[])]), body=[Expr(value=Call(func=Name(id=‘print’, ctx=Load()), args=[JoinedStr(values=[Constant(value=‘DBG test_str=’), FormattedValue(value=Name(id=‘test_str’, ctx=Load()), conversion=114)])], keywords=[]))]), match_case(pattern=MatchAs(), body=[Expr(value=Call(func=Name(id=‘print’, ctx=Load()), args=[JoinedStr(values=[Constant(value=‘DBG Not Blob’)])], keywords=[]))])]). Traceback (most recent call last): File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/main.py”, line 137, in <module> main() File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/main.py”, line 123, in main MainControl.main() File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/MainControl.py”, line 919, in main main_module = _createNodeTree(filename=filename) File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/MainControl.py”, line 117, in _createNodeTree main_module = Building.buildMainModuleTree( File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/tree/Building.py”, line 1136, in buildMainModuleTree module, _added = buildModule( File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/tree/Building.py”, line 1330, in buildModule createModuleTree( File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/tree/Building.py”, line 1099, in createModuleTree module_body = buildParseTree( File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/tree/Building.py”, line 762, in buildParseTree result = buildStatementsNode(provider=provider, nodes=body, source_ref=source_ref) File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/tree/TreeHelpers.py”, line 451, in buildStatementsNode statements = buildNodeList(provider, nodes, source_ref, allow_none=True) File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/tree/TreeHelpers.py”, line 360, in buildNodeList entry = buildNode(provider, node, node_source_ref, allow_none) File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/tree/TreeHelpers.py”, line 314, in buildNode result = build_nodes_args3[kind]( File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/tree/ReformulationMatchStatements.py”, line 425, in buildMatchNode _buildCase( File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/tree/ReformulationMatchStatements.py”, line 395, in _buildCase conditions, assignments = _buildMatch( File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/tree/ReformulationMatchStatements.py”, line 311, in _buildMatch or_conditions, or_assignments = _buildMatch( File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/tree/ReformulationMatchStatements.py”, line 328, in _buildMatch conditions, assignments = _buildMatchClass( File “/home/david/Dev/python/dev_venv3.10.2/lib/python3.10/site-packages/nuitka/tree/ReformulationMatchStatements.py”, line 260, in _buildMatchClass assert not pattern.patterns AssertionError
- Note if this is a regression
Unknown
- Consider getting commercial support
Not at this point
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top GitHub Comments
Part of 0.8 release that I just made.
Tested and works Kay - Thank you!