Skip to content

Commit 29aef76

Browse files
antonsyndclaude
andcommitted
feat: implement nested functions, collections.namedtuple, and tuple star-unpack (#507, #508, #509)
Phase 1 — Tuple star-unpack (#509): - Fix GenerateStarUnpacking to handle TupleType via ItemN access - Fix CheckStarUnpacking rest element type for heterogeneous tuples - Add tuple_star_unpack_tail and tuple_star_unpack_middle test fixtures Phase 2 — Nested functions (#507): - Register nested FunctionSymbols in enclosing scope during type checking - Emit nested functions as C# local functions (LocalFunctionStatementSyntax) - Save/restore method scope state around local function generation - Add nested_function_basic and nested_function_closure test fixtures Phase 3 — collections.namedtuple (#508): - Add Namedtuple stub to Sharpy.Core Collections module - Detect namedtuple("X", [...]) pattern in TypeChecker, synthesize TypeSymbol - Generate C# record class with ToString() override for Python repr format - Exempt namedtuple assignments from module-level statement validation - Add namedtuple_basic, namedtuple_print, match_named_tuple test fixtures Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f1c8222 commit 29aef76

26 files changed

Lines changed: 647 additions & 50 deletions
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
2
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from collections import namedtuple
2+
3+
Point = namedtuple("Point", ["x", "y"])
4+
5+
def main():
6+
p = Point(1, 2)
7+
print(p.x)
8+
print(p.y)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Color(r=255, g=128, b=0)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from collections import namedtuple
2+
3+
Color = namedtuple("Color", ["r", "g", "b"])
4+
5+
def main():
6+
c = Color(255, 128, 0)
7+
print(c)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1
2+
[2, 3, 4]
3+
5
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def main():
2+
first, *mid, last = (1, 2, 3, 4, 5)
3+
print(first)
4+
print(mid)
5+
print(last)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[1, 2, 3]
2+
4
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def main():
2+
*rest, last = (1, 2, 3, 4)
3+
print(rest)
4+
print(last)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Hello, World!
2+
Hello, Sharpy!
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def main():
2+
def greet(name: str) -> str:
3+
return f"Hello, {name}!"
4+
5+
print(greet("World"))
6+
print(greet("Sharpy"))

0 commit comments

Comments
 (0)