Skip to content

python's sum function causes internal issues, with the wrong type-hint #322

Closed
@Abhiram98

Description

@Abhiram98

I'm trying to use crosshair's diffbehavior analysis, to find the equivalence (or lack thereof) of these two functions:

def original(int_list: list[int]):
    count = 0
    for i in int_list:
       count +=i
    return count
def rewrite(int_list: list[int]):
    count = 0
    for sublist in int_list:
        count += sum(sublist)
    return count

Crosshair fails to find a conterexample, even though something simple like int_list=[123] would work. It seems like crosshair throws an internal error, which stops it from proceeding with its analysis. Here's a jist of the internal error

__exit__() Proxy intolerace: 'SymbolicInt' object is not iterable at Traceback (most recent call last):
  File "crosshair/diff_behavior.py", line 72, in describe_behavior
    ret = fn(*args.args, **args.kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "temp/test.py", line 5, in original
    for i in int_list:
             ^^^^^^^^
  File "crosshair/objectproxy.py", line 332, in __iter__
    return iter(self._wrapped())
           ^^^^^^^^^^^^^^^^^^^^^
TypeError: 'SymbolicInt' object is not iterable

PS: Thank you for the awesome tool!

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