Skip to content

[mypyc] Default of an i64 parameter is lost when compiled code calls the method on an interpreted subclass (fixed on master, still in 2.4.1) #22353

Closed as not planned

Description

@rob2244

Bug Report

When a native class has @mypyc_attr(allow_interpreted_subclasses=True) and a method with a parameter of type i64 (from mypy_extensions) that has a default, a call from compiled code that omits the argument gets 0 instead of the default when self is an instance of an interpreted (Python) subclass. The same call on an instance of the native class gets the default. A call from interpreted code on the subclass also gets the default. The subclass does not override the method.

We met this when compiling sqlglot with mypyc and subclassing its parser in Python: Parser._advance(self, times: i64 = 1) moved by 0 positions, so no statement parsed. A parameter typed int keeps its default, so our build rewrites these parameters to int as a workaround.

This no longer reproduces on master (ccbf32b). A bisect between the 2.4.1 merge base and master points at #22121 as the fix. Could that change be included in a 2.4.x release?

To Reproduce

base.py (compiled):

from mypy_extensions import i64, mypyc_attr


@mypyc_attr(allow_interpreted_subclasses=True)
class Parser:
    def __init__(self) -> None:
        self.index: i64 = 0

    def advance(self, times: i64 = 1) -> None:
        self.index += times

    def run(self) -> i64:
        self.advance()
        return self.index

main.py (interpreted):

from base import Parser


class Sub(Parser):  # interpreted subclass
    pass


print("compiled class:", Parser().run())  # expected 1
print("python subclass:", Sub().run())    # expected 1
s = Sub()
s.advance()
print("python subclass, called from Python:", s.index)  # expected 1
uv venv -p 3.14 .venv
uv pip install -p .venv mypy==2.4.1 setuptools
.venv/bin/mypyc base.py
.venv/bin/python main.py

Expected Behavior

compiled class: 1
python subclass: 1
python subclass, called from Python: 1

Actual Behavior

On mypy 2.4.1:

compiled class: 1
python subclass: 0
python subclass, called from Python: 1

On master (2.5.0+dev.ccbf32bd4) the output is the expected one.

Your Environment

  • Mypy version used: 2.4.1 (PyPI wheel); fixed on master ccbf32b
  • Mypy command-line flags: none (mypyc base.py)
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.14.3 (uv-managed CPython)
  • Operating system and version: macOS 26.5.2, arm64 (Apple silicon)

Activity

  1. rob2244 commented on Nov 3, 2026

    @rob2244
    Author

    Closing: filed by mistake. This is already fixed on master by #22121.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions