Skip to content

Fixed AstRewriter set comprehension logic#1

Open
Zayat wants to merge 1 commit intoawen-li:masterfrom
Zayat:ast-set-comprehension-fix
Open

Fixed AstRewriter set comprehension logic#1
Zayat wants to merge 1 commit intoawen-li:masterfrom
Zayat:ast-set-comprehension-fix

Conversation

@Zayat
Copy link

@Zayat Zayat commented Nov 24, 2022

The original code creates an empty dictionary {} and invokes add to add the elements, but 'dict' objects have no attribute 'add'.
Fix: create an empty set set().

Before/After Testing

Setup:

$ cd PolyCruise/PyComponent
$ echo -e "test = {i for i in [1,2,3,4,5,5,5,6]}\nprint(test)" > test_set_comprehension.py

Before:

$ python pyinspect.py -c test_set_comprehension.py
> assert(t.elts) # should be at least one element
> AssertionError

After:

$ python pyinspect.py -c test_set_comprehension.py
$ python Temp/test_set_comprehension.py
> {1, 2, 3, 4, 5, 6}

The original code creates an empty dictionary `{}` and invokes `add` to add the
elements, but 'dict' objects have no attribute 'add'.
Fix: create an empty set `set()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant