You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python: a subclass with no constructor gets a synthesised __init__(self) that hides its base class's constructor, so Derived(5) raises TypeError #149
PythonGenerator (Coder/Languages/PythonGenerator.cs:471-472) sets synthesiseConstructor whenever the class has a BaseType, even if it has no fields to initialise. It then writes a constructor (:495-505) that takes no arguments:
def__init__(self):
super().__init__()
Python constructors are inherited. Without this synthesised __init__, Derived would use Base.__init__ and accept its arguments. With it, Derived takes no arguments at all, and super().__init__() calls the base constructor without its required parameters.
Base has a constructor (x). Derived : Base has no members.
Derived(5)
# TypeError: Derived.__init__() takes 1 positional argument but 2 were given
Every subclass that relies on its base's constructor is broken. This came in with e2c5afa.
Suggested fix / acceptance criteria
Synthesise __init__ only when there are instance-initialised fields (instanceInitialisedFields.Count > 0). For a bare subclass, let Python inherit the base constructor.
When a constructor is synthesised for a subclass, forward the arguments:
def__init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# field initialisers
Add a Python execution test: base with a one-argument constructor, plus a derived class with no members and a derived class with an initialised field. Derived(5) constructs in both cases, and the base field is set.
Priority: High. Every generated Python subclass that relies on its base constructor raises TypeError at construction. That is a broad correctness break in one target.
Activity
matt-edmondson commentedon Oct 5, 2026
Triage
TypeErrorat construction. That is a broad correctness break in one target.Coder/Languages/PythonGenerator.cs(constructor synthesis). Suggested owner: @matt-edmondson, Python generatorlong(emitted as the undefined namelong) #109 (Pythonlongtype name, PR fix(PythonGenerator): map 'long' type to 'int' (#109) #124)Generated by Claude Code