Bug: Angle Brackets as Math Operators Corrupt Depth Parsing
Description
In gitgalaxy/core/detector.py, the _count_top_level_args method blindly treats angle brackets < and > as scope delimiters to support generics (e.g., List<String>). However, these characters double as math operators (less-than, greater-than, left-shift).
elif ch in "([{<":
depth += 1
elif ch in ")]}>":
if ch == ">" and i > 0 and body[i - 1] in "=-":
pass
elif depth > 0:
depth -= 1
Impact
When < or > is used as a math or comparison operator inside a default argument value, it corrupts the depth counter for the remainder of the parameter block:
- Less-than operator (
a = x < y): The < increments the depth counter permanently since there is no matching >. This causes all subsequent top-level commas to be ignored as if they were inside a generic bracket, resulting in severe undercounting.
- Greater-than operator (
a = (x > y, z)): The > prematurely decrements the depth counter. If it decrements the depth to 0, nested commas (like the one separating x > y and z) are exposed and erroneously counted as top-level argument separators, resulting in overcounting.
Steps to Reproduce
- Test with:
def foo(a = (x < y), b = 2) -> Returns 1 argument (undercounted).
- Test with:
def foo(a = (x > y, z), b = 2) -> Returns 3 arguments (overcounted).
Suggested Fix
Consider detecting whether < or > is part of a balanced generic block or surrounded by spaces/math structures to distinguish them from standard operators, or restrict their generic-bracket behavior solely to statically-typed languages.
Bug: Angle Brackets as Math Operators Corrupt Depth Parsing
Description
In
gitgalaxy/core/detector.py, the_count_top_level_argsmethod blindly treats angle brackets<and>as scope delimiters to support generics (e.g.,List<String>). However, these characters double as math operators (less-than, greater-than, left-shift).Impact
When
<or>is used as a math or comparison operator inside a default argument value, it corrupts the depth counter for the remainder of the parameter block:a = x < y): The<increments the depth counter permanently since there is no matching>. This causes all subsequent top-level commas to be ignored as if they were inside a generic bracket, resulting in severe undercounting.a = (x > y, z)): The>prematurely decrements the depth counter. If it decrements the depth to 0, nested commas (like the one separatingx > yandz) are exposed and erroneously counted as top-level argument separators, resulting in overcounting.Steps to Reproduce
def foo(a = (x < y), b = 2)-> Returns 1 argument (undercounted).def foo(a = (x > y, z), b = 2)-> Returns 3 arguments (overcounted).Suggested Fix
Consider detecting whether
<or>is part of a balanced generic block or surrounded by spaces/math structures to distinguish them from standard operators, or restrict their generic-bracket behavior solely to statically-typed languages.