Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Mypyc 1.13.0 crashes on specific match statement #18614

Description

@NiklasRosenstein

Crash Report

First time trying to compile my Python project with Mypyc; it seems to hang itself up on a specific match statement. Although there are a couple more in the code, it only complains about this one as far as I can tell. Replacing it with an semantically equivalent if-else gives me type warnings and errors instead (the expected result considering that these seem all valid).

Traceback

❯ uv run --with mypy[mypyc] mypyc -p nyl --show-traceback
Traceback (most recent call last):
  File "mypyc/irbuild/builder.py", line 272, in accept
  File "mypy/nodes.py", line 1648, in accept
  File "mypyc/irbuild/visitor.py", line 252, in visit_match_stmt
  File "mypyc/irbuild/statement.py", line 1022, in transform_match_stmt
  File "mypy/nodes.py", line 1648, in accept
  File "mypyc/irbuild/match.py", line 92, in visit_match_stmt
  File "mypy/patterns.py", line 150, in accept
  File "mypyc/irbuild/match.py", line 164, in visit_class_pattern
src/nyl/generator/components.py:81: AssertionError: 

To Reproduce

  1. Clone https://github.com/helsing-ai/nyl and check out 0.8.1 (that is HEAD today)
  2. Run uv run --with mypy[mypyc]==1.13.0 mypyc -p nyl

The specific piece of code that it seems to hiccup on is this:

https://github.com/helsing-ai/nyl/blob/659ffec8e4b8362f8012e0b096fe4b2606861586/src/nyl/generator/components.py#L81-L92

        match component:
            case HelmComponent(path):
                chart = HelmChart(
                    metadata=instance.metadata,
                    spec=HelmChartSpec(
                        chart=ChartRef(path=str(path.resolve())),
                        values={"metadata": resource["metadata"], **instance.spec},
                    ),
                )
                return self.helm_generator.generate(chart)
            case _:
                raise RuntimeError(f"unexpected component type: {component}")

There are a couple more match statements in the code which it doesn't seem to complain about after changing this to use if-else instead. I'm not exactly sure where best to start to reduce it to a smaller example.

Your Environment

  • Mypy version used: 1.13.0
  • Mypy command-line flags: -p nyl
  • Mypy configuration options from mypy.ini (and other config files):
    explicit_package_bases = true
    namespace_packages = true
    show_column_numbers = true
    strict = true
    mypy_path = ["src"]
    
  • Python version used: 3.11.9
  • Operating system and version: WSL2 Ubuntu 22.04.5 LTS

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions